19 #ifndef _DATAHASHTABLE_H_ 20 #define _DATAHASHTABLE_H_ 28 #define HASHTABLE_FILLFACTOR 0.7 75 template <
class HashItem,
class Info >
84 template <
class ElemHashItem,
class ElemInfo >
100 typedef Element< HashItem, Info >
Elem;
129 bool has(
const HashItem& h)
const 131 return index(h) >= 0;
139 const Info*
get(
const HashItem& h)
const 143 return (i >= 0) ? &m_elem[i].info : 0;
156 return m_elem[
index(h)].info;
170 reMax(
int(m_memfactor * m_used) + 1);
172 assert(m_used < m_elem.
size());
184 m_elem[i].info =
info;
193 void remove(
const HashItem& h)
204 for(
int i = 0; i < m_elem.
size(); i++)
214 void reMax (
int newSize = -1,
int newHashSize = 0)
218 m_elem.
reSize(newSize < m_used ? m_used : newSize);
222 m_hashsize = (newHashSize < 1) ?
autoHashSize() : newHashSize;
224 for(
int i = 0; i < save.
size(); i++)
236 #ifdef ENABLE_CONSISTENCY_CHECKS 239 for(
int i = 0; i < m_elem.
size(); i++)
275 int (*hashfun)(
const HashItem*),
281 , m_memfactor(factor)
295 primes[10] = 3680893;
296 primes[11] = 5693959;
297 primes[12] = 7753849;
298 primes[13] = 9849703;
299 primes[14] = 11973277;
300 primes[15] = 14121853;
301 primes[16] = 17643961;
302 primes[17] = 24273817;
303 primes[18] = 32452843;
304 primes[19] = 49979687;
305 primes[20] = 67867967;
306 primes[21] = 86028121;
307 primes[22] = 104395301;
308 primes[23] = 122949823;
309 primes[24] = 141650939;
310 primes[25] = 160481183;
311 primes[26] = 179424673;
312 primes[27] = 198491317;
313 primes[28] = 217645177;
314 primes[29] = 256203161;
315 primes[30] = 314606869;
316 primes[31] = 373587883;
317 primes[32] = 433024223;
318 primes[33] = 492876847;
319 primes[34] = 553105243;
320 primes[35] = 613651349;
321 primes[36] = 694847533;
322 primes[37] = 756065159;
323 primes[38] = 817504243;
324 primes[39] = 879190747;
325 primes[40] = 941083981;
326 primes[41] = 982451653;
327 primes[42] = INT_MAX;
330 m_hashsize = (hashsize < 1) ?
autoHashSize() : hashsize;
332 assert(m_memfactor > 1.0);
347 assert(m_memfactor > 1.0);
354 : m_elem(base.m_elem)
356 , m_memfactor(base.m_memfactor)
357 , m_used(base.m_used)
358 , m_hashsize(base.m_hashsize)
359 , primes(base.primes)
360 , nprimes(base.nprimes)
362 assert(m_memfactor > 1.0);
378 int oldsize = m_elem.
size();
381 int right = nprimes - 1;
384 while( left <= right)
386 middle = (left + right) / 2;
388 if( oldsize < primes[middle])
392 else if( oldsize > primes[middle])
398 assert(oldsize == primes[middle]);
399 return primes[middle + 1];
403 assert(left == right + 1);
417 int maxsize = m_elem.
size();
420 for (i = 2; i < maxsize; i++)
423 for (i = 2; i < maxsize; ++i)
427 for (
int j = i; j < maxsize; j += i)
430 if (m_elem.
size() % i != 0)
434 if (hashsize > maxsize)
460 assert(m_elem.
size() > 0);
462 int i = (*m_hashfun)(&h) % m_elem.
size();
468 && (m_elem[i].
item == h))
483 #endif // _DATAHASHTABLE_H_ Safe arrays of data objects.Class DataArray provides safe arrays of Data Objects. For general C++ obj...
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.
Element< HashItem, Info > Elem
void clear()
remove all entries from DataHashTable.
#define HASHTABLE_FILLFACTOR
bool isConsistent() const
consistency check
element had been used, but released
template class for elements stored in the hash table
int index(const HashItem &h) const
returns hash index of HashItem h or -1, if h is not present.
int primes[50]
some prime numbers for fast access
DataArray< Elem > m_elem
stores all elements of the hash table
int size() const
return nr. of elements.
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...
int autoHashSize() const
determine a good m_hashsize.
Debugging, floating point type and parameter definitions.
states
States of an element.
bool has(const HashItem &h) const
Is item h present in DataHashTable?
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.
int(* m_hashfun)(const HashItem *)
pointer to hash function (mapping: HashItem -> int)
const Info & operator[](const HashItem &h) const
references Info of HashItem h.
bool isConsistent() const
checks whether DataHashTable is consistent
int autoHashSizeold() const
automatically computes a good m_hashsize.
int nprimes
number of stored prime numbers
int m_hashsize
increment added to hash index, if allready used
#define MSGinconsistent(name)
void reSize(int newsize)
reset size to newsize.
void reMax(int newSize=-1, int newHashSize=0)
reset size of the DataHashTable.
enum soplex::DataHashTable::Element::states stat