28#ifndef _DATAHASHTABLE_H_
29#define _DATAHASHTABLE_H_
40#define SOPLEX_HASHTABLE_FILLFACTOR 0.7
87template <
class HashItem,
class Info >
96 template <
class ElemHashItem,
class ElemInfo >
141 bool has(
const HashItem& h)
const
143 return index(h) >= 0;
151 const Info*
get(
const HashItem& h)
const
155 return (i >= 0) ? &
m_elem[i].info :
nullptr;
177 void add(
const HashItem& h,
const Info& info)
186 decltype(
m_elem.size()) i;
220 for(
int i = 0; i <
m_elem.size(); i++)
231 void reMax(
int newSize = -1,
int newHashSize = 0)
241 for(
int i = 0; i < save.
size(); i++)
243 add(save[i].item, save[i].info);
253#ifdef ENABLE_CONSISTENCY_CHECKS
256 for(
int i = 0; i <
m_elem.size(); i++)
270 return m_elem.isConsistent();
294 int (*hashfun)(
const HashItem*),
397 auto oldsize =
m_elem.size();
405 middle = (left + right) / 2;
407 if(oldsize <
primes[middle])
411 else if(oldsize >
primes[middle])
417 assert(oldsize ==
primes[middle]);
418 return primes[middle + 1];
422 assert(left == right + 1);
436 int maxsize =
m_elem.size();
439 for(i = 2; i < maxsize; i++)
442 for(i = 2; i < maxsize; ++i)
446 for(
int j = i; j < maxsize; j += i)
449 if(
m_elem.size() % i != 0)
453 if(hashsize > maxsize)
480 assert(
m_elem.size() > 0);
482 auto i = (*m_hashfun)(&h) %
m_elem.size();
Save arrays of arbitrary types.
Safe arrays of arbitrary types.
int size() const
return the number of elements.
template class for elements stored in the hash table
enum soplex::DataHashTable::Element::states stat
states
States of an element.
@ RELEASED
element had been used, but released
@ FREE
element has never been used
Generic hash table for data objects.
bool has(const HashItem &h) const
Is item h present in DataHashTable?
Array< Elem > m_elem
stores all elements of the hash table
const Info * get(const HashItem &h) const
returns const pointer to Info of HashItem h or 0, if item is not found.
Real m_memfactor
memory is reMax()ed by this factor if a new element does't fit
bool isConsistent() const
checks whether DataHashTable is consistent
int(* m_hashfun)(const HashItem *)
pointer to hash function (mapping: HashItem -> int)
void remove(const HashItem &h)
remove HashItem h from the DataHashTable.
DataHashTable & operator=(const DataHashTable &base)
assignment operator.
int nprimes
number of stored prime numbers
Element< HashItem, Info > Elem
int m_used
current number of entries in the hash table
void reMax(int newSize=-1, int newHashSize=0)
reset size of the DataHashTable.
int m_hashsize
increment added to hash index, if allready used
int autoHashSize() const
determine a good m_hashsize.
const Info & operator[](const HashItem &h) const
references Info of HashItem h.
int primes[50]
some prime numbers for fast access
DataHashTable(int(*hashfun)(const HashItem *), int maxsize=265, int hashsize=0, Real factor=2.0)
default constructor.
void add(const HashItem &h, const Info &info)
adds a new entry to the hash table.
void clear()
remove all entries from DataHashTable.
DataHashTable(const DataHashTable &base)
copy constructor.
int index(const HashItem &h) const
returns hash index of HashItem h or -1, if h is not present.
int autoHashSizeold() const
automatically computes a good m_hashsize.
#define SOPLEX_HASHTABLE_FILLFACTOR
Everything should be within this namespace.
Debugging, floating point type and parameter definitions.
#define SPX_MSG_INCONSISTENT(name)