#include <hashtable.h>
Collaboration diagram for Hashtable< KEY, VALUE, SIZ >:

Public Types | |
| typedef std::vector< HashElement > | vector_type |
| The type of the table, so that it can be changed fairly easily later. More... | |
| typedef HashElement | value_type |
| To make the Hashtable more similar to STL. More... | |
| typedef HashIterator< typename vector_type::iterator > | iterator |
| So that users can use an iterator of the private typedef. More... | |
| typedef HashIterator< typename vector_type::const_iterator > | const_iterator |
| So that users can use an iterator of the private typedef. More... | |
Public Methods | |
| vector_type & | GetAll (const KEY &key) |
| Gets all contents of this hashtable in the KEY th table. More... | |
| VALUE * | Get (const KEY &key) |
| Gets the first value with this key. More... | |
| const VALUE * | Get (const KEY &key) const |
| bool | Get (const KEY &key, VALUE &k) |
| iterator | find (const KEY &key) |
| Gets an iterator with the first value with the key. More... | |
| const_iterator | find (const KEY &key) const |
| Gets a const iterator with the first value with the key (for const versions of this class). More... | |
| void | Put (const KEY &key, const VALUE &value) |
| adds this key/value pair without checking duplicates. More... | |
| iterator | insert (value_type valty) |
| adds this key/value pair without checking duplicates. More... | |
| void | Delete (const KEY &key) |
| Deletes the earlierst copy of value in the table with this key (does not delete the memory associated with the pointer). More... | |
| iterator | erase (const iterator &iter) |
| Erases the item in the requested array. More... | |
| unsigned int | size (int vectorname) const |
| Returns the size of the specified vector. More... | |
| std::vector< VALUE * > | GetAll () const |
| Gets all contents of this hashtable. More... | |
| VALUE * | Get (const KEY &key) const |
| Gets the first value with this key. More... | |
| void | Put (const KEY &key, VALUE *value) |
| Adds this key/value pair without checking duplicates. More... | |
| void | Delete (const KEY &key) |
| Deletes the earlierst copy of value in the table with this key (does not delete the memory associated with the pointer). More... | |
Static Public Methods | |
| template<class Type> int | hash (const Type key) |
| The generic hash function given an int. More... | |
| int | hash (const std::string &key) |
| the generic hash function given a string:notes that strings generally are 7 bits per char.FIXME: Should take into account that most stuffage is between 64 and 128 somehow. More... | |
Private Types | |
| typedef std::pair< KEY, VALUE > | HashElement |
| A single element in the hash table. More... | |
Private Methods | |
| void | swapiter (iterator iter1, iterator iter2) |
| iterator | SwapIn (vector_type *tbl, HashElement elem) |
Static Private Methods | |
| int | hash (const int key) |
| the hash function that creates a hashval from an int by modding it by SIZ . More... | |
| int | hash (const std::string &key) |
| the generic hash function given a string:notes that strings generally are 7 bits per char.FIXME: Should take into account that most stuffage is between 64 and 128 somehow. More... | |
Private Attributes | |
| vector_type | table [SIZ] |
| Where the actual elements are stored, a statically sized table. More... | |
| std::vector< HashElement > | table [SIZ] |
| This is an array of vector s of the HashElement structure, which contains a KEY and a VALUE . More... | |
| Key | k |
| VALUE * | val |
|
|||||
|
So that users can use an iterator of the private typedef.
|
|
|||||
|
A single element in the hash table.
|
|
|||||
|
So that users can use an iterator of the private typedef.
|
|
|||||
|
To make the Hashtable more similar to STL.
|
|
|||||
|
The type of the table, so that it can be changed fairly easily later.
|
|
||||||||||
|
Deletes the earlierst copy of value in the table with this key (does not delete the memory associated with the pointer).
|
|
||||||||||
|
Deletes the earlierst copy of value in the table with this key (does not delete the memory associated with the pointer).
00220 {
00221 int hashval = hash(key);
00222 typename vector_type::iterator iter = table[hashval].begin(), end = table[hashval].end();
00223
00224 for(;iter!=end;iter++)
00225 if((*iter).key == key)
00226 break;
00227 if(iter==end)
00228 return;
00229 else {
00230 table[hashval].erase(iter);
00231 }
00232 }
|
|
||||||||||
|
Erases the item in the requested array.
00234 {
00235 iterator ret(iter.key,iter.v,iter.v->erase(iter.i));
00236 ret.findnext();
00237 return ret;
00238 }
|
|
||||||||||
|
Gets a const iterator with the first value with the key (for const versions of this class). The returned value contains: .first == iterator in the array EX: (*find(...).first).second is VALUE. .second == integer number of the array needed (for calls to end() and begin())
00201 {
00202 int tablenum=hash(key);
00203 const vector_type *mytyp=&table[tablenum];
00204 return const_iterator (key, mytyp);
00205 }
|
|
||||||||||
|
Gets an iterator with the first value with the key. The returned value contains: .first == iterator in the array EX: (*find(...).first).second is VALUE. .second == integer number of the array needed (for calls to end() and begin())
00191 {
00192 int tablenum=hash(key);
00193 vector_type *mytyp=&table[tablenum];
00194 return iterator(key, mytyp);
00195 }
|
|
||||||||||
|
Gets the first value with this key.
|
|
||||||||||||||||
|
|
|
||||||||||
|
00165 {
00166 int hashval = hash(key);
00167 typename vector_type::const_iterator iter = table[hashval].find(key);
00168 typename vector_type::const_iterator end = table[hashval].end();
00169 for(;iter!=end;iter++)
00170 if((*iter).first == key)
00171 break;
00172 if (iter==end)
00173 return NULL;
00174 else
00175 return &(*iter).second;
00176 }
|
|
||||||||||
|
Gets the first value with this key.
00152 {
00153 int hashval = hash(key);
00154 typename vector_type::iterator iter = table[hashval].begin();
00155 typename vector_type::const_iterator end = table[hashval].end();
00156 for(;;iter++) {
00157 if (iter==end)
00158 return NULL;
00159 if((*iter).first == key)
00160 break;
00161 }
00162 return &(*iter).second;
00163 }
|
|
|||||||||
|
Gets all contents of this hashtable.
|
|
||||||||||
|
Gets all contents of this hashtable in the KEY th table. WARNING: GetAll will return ALL contents of the table in which key lies, and MAY return unexpected VALUE s. This does make GetAll faster than other methods of getting
|
|
||||||||||
|
the generic hash function given a string:notes that strings generally are 7 bits per char.FIXME: Should take into account that most stuffage is between 64 and 128 somehow.
|
|
||||||||||
|
the hash function that creates a hashval from an int by modding it by SIZ .
00083 {
00084 return ((unsigned int)key)%SIZ;
00085 }
|
|
||||||||||
|
the generic hash function given a string:notes that strings generally are 7 bits per char.FIXME: Should take into account that most stuffage is between 64 and 128 somehow.
|
|
||||||||||||||
|
The generic hash function given an int.
00039 {
00040 return ((unsigned int)key)%SIZ;
00041 }
|
|
||||||||||
|
adds this key/value pair without checking duplicates.
00212 {
00213 int hashval = hash(valty.first);
00214 vector_type &tab=table[hashval];
00215 tab.push_back (valty);
00216 return iterator(valty.first, &tab, tab.end()-1);//fulliterator (SwapIn(table[hashval],valty), hashval);
00217 }
|
|
||||||||||||||||
|
Adds this key/value pair without checking duplicates.
|
|
||||||||||||||||
|
adds this key/value pair without checking duplicates.
00207 {
00208 int hashval = hash(key);
00209 table[hashval].push_back(HashElement(key, value));
00210 }
|
|
||||||||||
|
Returns the size of the specified vector. This is usually used to check for the array bounds
00241 {
00242 return table[vectorname].size();
00243 }
|
|
||||||||||||||||
|
00135 {
00136 tbl.push_back(elem);
00137 iterator iter=tbl.back()-1;
00138 return iter;
00139 }
|
|
||||||||||||||||
|
00130 {
00131 value_type backup=(*iter1);
00132 (*iter1)=(*iter2);
00133 (*iter2)=backup;
00134 }
|
|
|||||
|
|
|
|||||
|
This is an array of vector s of the HashElement structure, which contains a KEY and a VALUE .
|
|
|||||
|
Where the actual elements are stored, a statically sized table.
|
|
|||||
|
|
1.2.15