DataHashTable< HashItem, Info > Class Template Reference Generic hash table for data objects.Class DataHashTable provides a generic hash table for Data Objects, i.e., a map that maps arguments called HashItems to values called Infos. HashItem and Info types are passed as template arguments. HashItems must provide a comparison operator==(). Furthermore, both the HashItem and Info must be data objects in the sense that the assignment operator is equivalent to a
Detailed Descriptiontemplate<class HashItem, class Info>
|
|
explicit |
default constructor.
Allocates a DataHashTable for maxsize
entries using hashfun
as hash function. If hashsize
> 0, m_hashsize is set to the specified value, otherwise a suitable hash size is computed automatically. Parameter factor
is used for memory management: If more than maxsize
entries are added to the DataHashTable, it will automatically be reMax()ed by a factor of factor
.
hashfun | pointer to hash function. |
maxsize | maximum number of hash elements. |
hashsize | hash size. |
factor | factor for increasing data block. |
Definition at line 274 of file datahashtable.h.
DataHashTable | ( | const DataHashTable< HashItem, Info > & | base | ) |
copy constructor.
Definition at line 353 of file datahashtable.h.
void add | ( | const HashItem & | h, |
const Info & | info | ||
) |
adds a new entry to the hash table.
Adds a new entry consisting of HashItem h
and Info info
to the DataHashTable. No entry with HashItem h
must be in the DataHashTable yet. After completion, info
may be accessed via get() or operator[]() with h
as parameter. The DataHashTable is reMax()ed if it becomes neccessary.
Definition at line 165 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::reMax().
|
private |
determine a good m_hashsize.
Determine next larger prime number for new m_hashsize
Definition at line 376 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::DataHashTable(), and DataHashTable< soplex::NameSet::Name, soplex::DataKey >::reMax().
|
private |
automatically computes a good m_hashsize.
Computes a good m_hashsize as the product of all prime numbers not divisors of the number of elements that are <= the maximum divisor of the number of elemens.
Definition at line 413 of file datahashtable.h.
void clear | ( | ) |
remove all entries from DataHashTable.
Definition at line 202 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::DataHashTable(), and DataHashTable< soplex::NameSet::Name, soplex::DataKey >::reMax().
const Info* get | ( | const HashItem & | h | ) | const |
returns const pointer to Info of HashItem h
or 0, if item is not found.
Returns a pointer to Info component of hash element h
or a zero pointer if element h
is not in the table.
Definition at line 139 of file datahashtable.h.
Referenced by NameSet::key(), and NameSet::number().
bool has | ( | const HashItem & | h | ) | const |
Is item h
present in DataHashTable?
Definition at line 129 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::add(), NameSet::has(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::isConsistent(), NameSet::number(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::operator[](), and DataHashTable< soplex::NameSet::Name, soplex::DataKey >::remove().
|
private |
returns hash index of HashItem h
or -1, if h
is not present.
Using the hash function m_hashfun, the hash value of h
is calculated. Starting with this hash index, every m_hashsize%-th element is compared with h
until h
is found or all elements have been checked.
h | HashItem, for which the hash index should be calculated |
h
or -1, if h
is not a member of the hash table Definition at line 455 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::get(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::has(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::operator[](), and DataHashTable< soplex::NameSet::Name, soplex::DataKey >::remove().
bool isConsistent | ( | ) | const |
checks whether DataHashTable is consistent
Definition at line 234 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::DataHashTable(), and DataHashTable< soplex::NameSet::Name, soplex::DataKey >::operator=().
DataHashTable& operator= | ( | const DataHashTable< HashItem, Info > & | base | ) |
assignment operator.
Definition at line 337 of file datahashtable.h.
const Info& operator[] | ( | const HashItem & | h | ) | const |
references Info of HashItem h
.
Index operator for accessing the Info associated to HashItem h
. It is required that h
belongs to the DataHashTable, otherwise it core dumps. Methods has() or get() can be used for inquiring wheater h
belongs to the DataHashTable or not.
Definition at line 152 of file datahashtable.h.
void reMax | ( | int | newSize = -1 , |
int | newHashSize = 0 |
||
) |
reset size of the DataHashTable.
Reset the maximum number of elements of a DataHashTable to newSize
. However, if newSize
< m_used, it is resized to m_used only. If newHashSize
< 1, a new hash size is computed automatically. Otherwise, the specified value will be taken.
Definition at line 214 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::add().
void remove | ( | const HashItem & | h | ) |
remove HashItem h
from the DataHashTable.
Definition at line 193 of file datahashtable.h.
stores all elements of the hash table
Definition at line 107 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::operator=().
|
private |
pointer to hash function (mapping: HashItem -> int)
Definition at line 113 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::add(), and DataHashTable< soplex::NameSet::Name, soplex::DataKey >::operator=().
|
private |
increment added to hash index, if allready used
Definition at line 109 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::add(), DataHashTable< soplex::NameSet::Name, soplex::DataKey >::index(), and DataHashTable< soplex::NameSet::Name, soplex::DataKey >::operator=().
|
private |
memory is reMax()ed by this factor if a new element does't fit
Definition at line 115 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::operator=().
|
private |
current number of entries in the hash table
Definition at line 111 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::operator=().
|
private |
number of stored prime numbers
Definition at line 119 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::operator=().
|
private |
some prime numbers for fast access
Definition at line 117 of file datahashtable.h.
Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::operator=().