19 #ifndef _DATAHASHTABLE_H_ 20 #define _DATAHASHTABLE_H_ 29 #define HASHTABLE_FILLFACTOR 0.7 76 template <
class HashItem,
class Info >
85 template <
class ElemHashItem,
class ElemInfo >
101 typedef Element< HashItem, Info >
Elem;
130 bool has(
const HashItem& h)
const 132 return index(h) >= 0;
140 const Info*
get(
const HashItem& h)
const 144 return (i >= 0) ? &m_elem[i].info :
nullptr;
157 return m_elem[
index(h)].info;
171 reMax(
int(m_memfactor * m_used) + 1);
173 assert(m_used < m_elem.
size());
175 decltype(m_elem.
size()) i;
185 m_elem[i].info =
info;
194 void remove(
const HashItem& h)
209 for(
int i = 0; i < m_elem.
size(); i++)
220 void reMax(
int newSize = -1,
int newHashSize = 0)
224 m_elem.
reSize(newSize < m_used ? m_used : newSize);
228 m_hashsize = (newHashSize < 1) ?
autoHashSize() : newHashSize;
230 for(
int i = 0; i < save.
size(); i++)
242 #ifdef ENABLE_CONSISTENCY_CHECKS 245 for(
int i = 0; i < m_elem.
size(); i++)
283 int (*hashfun)(
const HashItem*),
289 , m_memfactor(factor)
303 primes[10] = 3680893;
304 primes[11] = 5693959;
305 primes[12] = 7753849;
306 primes[13] = 9849703;
307 primes[14] = 11973277;
308 primes[15] = 14121853;
309 primes[16] = 17643961;
310 primes[17] = 24273817;
311 primes[18] = 32452843;
312 primes[19] = 49979687;
313 primes[20] = 67867967;
314 primes[21] = 86028121;
315 primes[22] = 104395301;
316 primes[23] = 122949823;
317 primes[24] = 141650939;
318 primes[25] = 160481183;
319 primes[26] = 179424673;
320 primes[27] = 198491317;
321 primes[28] = 217645177;
322 primes[29] = 256203161;
323 primes[30] = 314606869;
324 primes[31] = 373587883;
325 primes[32] = 433024223;
326 primes[33] = 492876847;
327 primes[34] = 553105243;
328 primes[35] = 613651349;
329 primes[36] = 694847533;
330 primes[37] = 756065159;
331 primes[38] = 817504243;
332 primes[39] = 879190747;
333 primes[40] = 941083981;
334 primes[41] = 982451653;
335 primes[42] = INT_MAX;
338 m_hashsize = (hashsize < 1) ?
autoHashSize() : hashsize;
340 assert(m_memfactor > 1.0);
355 assert(m_memfactor > 1.0);
362 : m_elem(base.m_elem)
364 , m_memfactor(base.m_memfactor)
365 , m_used(base.m_used)
366 , m_hashsize(base.m_hashsize)
367 , primes(base.primes)
368 , nprimes(base.nprimes)
370 assert(m_memfactor > 1.0);
386 auto oldsize = m_elem.
size();
389 int right = nprimes - 1;
394 middle = (left + right) / 2;
396 if(oldsize < primes[middle])
400 else if(oldsize > primes[middle])
406 assert(oldsize == primes[middle]);
407 return primes[middle + 1];
411 assert(left == right + 1);
425 int maxsize = m_elem.
size();
428 for(i = 2; i < maxsize; i++)
431 for(i = 2; i < maxsize; ++i)
435 for(
int j = i; j < maxsize; j += i)
438 if(m_elem.
size() % i != 0)
442 if(hashsize > maxsize)
469 assert(m_elem.
size() > 0);
471 auto i = (*m_hashfun)(&h) % m_elem.
size();
477 && (m_elem[i].
item == h))
493 #endif // _DATAHASHTABLE_H_
int size() const
return the number of elements.
bool isConsistent() const
Consistency check.
element has never been used
DataHashTable(int(*hashfun)(const HashItem *), int maxsize=265, int hashsize=0, Real factor=2.0)
default constructor.
DataHashTable(const DataHashTable &base)
copy constructor.
Safe arrays of arbitrary types.Class Array provides safe arrays of arbitrary type. Array elements are accessed just like ordinary C++ array elements by means of the index operator[](). Safety is provided by.
Element< HashItem, Info > Elem
bool isConsistent() const
checks whether DataHashTable is consistent
Array< Elem > m_elem
stores all elements of the hash table
void clear()
remove all entries from DataHashTable.
#define HASHTABLE_FILLFACTOR
int index(const HashItem &h) const
returns hash index of HashItem h or -1, if h is not present.
element had been used, but released
template class for elements stored in the hash table
int primes[50]
some prime numbers for fast access
int autoHashSizeold() const
automatically computes a good m_hashsize.
int autoHashSize() const
determine a good m_hashsize.
int m_used
current number of entries in the hash table
DataHashTable & operator=(const DataHashTable &base)
assignment operator.
Generic hash table for data objects.Class DataHashTable provides a generic hash table for Data Object...
const Info & operator[](const HashItem &h) const
references Info of HashItem h.
Debugging, floating point type and parameter definitions.
states
States of an element.
Real m_memfactor
memory is reMax()ed by this factor if a new element does't fit
Everything should be within this namespace.
void add(const HashItem &h, const Info &info)
adds a new entry to the hash table.
void reSize(int newsize)
reset the number of elements.
int(* m_hashfun)(const HashItem *)
pointer to hash function (mapping: HashItem -> int)
Save arrays of arbitrary types.
int nprimes
number of stored prime numbers
int m_hashsize
increment added to hash index, if allready used
bool has(const HashItem &h) const
Is item h present in DataHashTable?
#define MSGinconsistent(name)
void reMax(int newSize=-1, int newHashSize=0)
reset size of the DataHashTable.
enum soplex::DataHashTable::Element::states stat