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++)
215 void reMax(
int newSize = -1,
int newHashSize = 0)
219 m_elem.
reSize(newSize < m_used ? m_used : newSize);
223 m_hashsize = (newHashSize < 1) ?
autoHashSize() : newHashSize;
225 for(
int i = 0; i < save.
size(); i++)
237 #ifdef ENABLE_CONSISTENCY_CHECKS 240 for(
int i = 0; i < m_elem.
size(); i++)
278 int (*hashfun)(
const HashItem*),
284 , m_memfactor(factor)
298 primes[10] = 3680893;
299 primes[11] = 5693959;
300 primes[12] = 7753849;
301 primes[13] = 9849703;
302 primes[14] = 11973277;
303 primes[15] = 14121853;
304 primes[16] = 17643961;
305 primes[17] = 24273817;
306 primes[18] = 32452843;
307 primes[19] = 49979687;
308 primes[20] = 67867967;
309 primes[21] = 86028121;
310 primes[22] = 104395301;
311 primes[23] = 122949823;
312 primes[24] = 141650939;
313 primes[25] = 160481183;
314 primes[26] = 179424673;
315 primes[27] = 198491317;
316 primes[28] = 217645177;
317 primes[29] = 256203161;
318 primes[30] = 314606869;
319 primes[31] = 373587883;
320 primes[32] = 433024223;
321 primes[33] = 492876847;
322 primes[34] = 553105243;
323 primes[35] = 613651349;
324 primes[36] = 694847533;
325 primes[37] = 756065159;
326 primes[38] = 817504243;
327 primes[39] = 879190747;
328 primes[40] = 941083981;
329 primes[41] = 982451653;
330 primes[42] = INT_MAX;
333 m_hashsize = (hashsize < 1) ?
autoHashSize() : hashsize;
335 assert(m_memfactor > 1.0);
350 assert(m_memfactor > 1.0);
357 : m_elem(base.m_elem)
359 , m_memfactor(base.m_memfactor)
360 , m_used(base.m_used)
361 , m_hashsize(base.m_hashsize)
362 , primes(base.primes)
363 , nprimes(base.nprimes)
365 assert(m_memfactor > 1.0);
381 int oldsize = m_elem.
size();
384 int right = nprimes - 1;
389 middle = (left + right) / 2;
391 if(oldsize < primes[middle])
395 else if(oldsize > primes[middle])
401 assert(oldsize == primes[middle]);
402 return primes[middle + 1];
406 assert(left == right + 1);
420 int maxsize = m_elem.
size();
423 for(i = 2; i < maxsize; i++)
426 for(i = 2; i < maxsize; ++i)
430 for(
int j = i; j < maxsize; j += i)
433 if(m_elem.
size() % i != 0)
437 if(hashsize > maxsize)
464 assert(m_elem.
size() > 0);
466 int i = (*m_hashfun)(&h) % m_elem.
size();
472 && (m_elem[i].
item == h))
488 #endif // _DATAHASHTABLE_H_ Safe arrays of data objects.Class DataArray provides safe arrays of Data Objects. For general C++ obj...
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.
Element< HashItem, Info > Elem
bool isConsistent() const
checks whether DataHashTable is consistent
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
DataArray< Elem > m_elem
stores all elements of the hash table
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.
int(* m_hashfun)(const HashItem *)
pointer to hash function (mapping: HashItem -> int)
int size() const
return nr. of elements.
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 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