#include <hash.h>
Public Methods | |
Hash () | |
Default constructor. | |
~Hash () | |
Destructor. | |
void | clear () |
Clears the whole hashtable. More... | |
T * | first () |
Gets the first item in the hash table for iterating. More... | |
T * | next (T *item) |
Gets next item for iterating. More... | |
T * | addNoRehash (T *item) |
Adds an item to the hash table without rehashing. More... | |
T * | add (T *item) |
Adds an item to the hash table. More... | |
T * | removeNoRehash (T *item) |
Removes an item from the hash table without rehashing. More... | |
T * | remove (T *item) |
Removes an item from the hash table. More... | |
T * | get (const K &key) |
Searches the hash table for an item corresponing to the specified key. More... | |
int | forEach (int(*f)(T *, void **), void **inout) |
Same action for each item of the hashtable. More... | |
Private Types | |
enum | e { HASH_LIST_LIMIT = 3 } |
constants. More... | |
Private Methods | |
unsigned int | makeIndex (int x) |
Converts argument to an index to the hash table. More... | |
void | rehash (unsigned int sz) |
Rehashing. More... | |
Private Attributes | |
List< T, L > * | _table |
an array of lists. | |
unsigned int | _size |
size of hashtable. | |
unsigned int | _mask |
hash mask. | |
unsigned int | _numItems |
number of items in the whole hashtable. | |
unsigned int | _index |
temporary index used for iteration. |
This template implements hashing by using existing List template implementation. It should be faster than normal lists. Items are divided into several lists (number of them dynamically changes) depending on the value of their keys.
In order to store objects of type T in this hash table, the class T must meet following requirements:
First, 'const K& T::getKey(K&)' method must be defined, which is serves for object's key retrivial. The type of the key is specified through the template parameter K.
Second, 'int T::operator==(const K &)' must be defined, which is used to compare an object with a given key.
Third, the class must contain a custom hash function in the form of a static method 'static int T::hashKey(const K&)', which is used to transform keys to integers.
Fourth, the class must be inhereted from the ListItem class directly, or undirectly through one of LI1, LI2, etc. classes. The actual base class is then represented by the template parameter L.
Note: The whole object is inserted, not only pointer to it !!! Therefore each item can be in the hashtable only once !!! Different hashtables can use different list item types (LI1, LI2 etc.) for their lists, so it is possible to have the same object in more than one hashtable.
T | type of object in the hashtable |
K | type of key thru which the hashing is done |
L | type of list item used for lists (LI1, LI2 etc.) |
Definition at line 81 of file hash.h.
|
constants.
|
|
Adds an item to the hash table.
Definition at line 201 of file hash.h. Referenced by addNoRehash(), Prof::event_classLoad(), Prof::event_jniGlobalrefAlloc(), Prof::event_jniWeakGlobalrefAlloc(), Prof::event_objectAlloc(), Prof::event_objectMove(), Prof::event_threadStart(), Prof::getAllocObject(), Prof::getAllocObjectMethod(), Prof::getAllocObjectTrace(), Prof::getAllocThreadMethod(), Prof::getAllocThreadObject(), Prof::getAllocThreadObjectMethod(), Prof::getAllocThreadObjectTrace(), Prof::getAllocThreadTrace(), Prof::getAllocTrace(), Prof::getCpuThreadMethod(), Prof::getCpuThreadTrace(), Prof::getCpuTrace(), Prof::getMonThreadMethod(), Prof::getMonThreadTrace(), and Prof::getMonTrace().
|
|
Adds an item to the hash table without rehashing.
Definition at line 180 of file hash.h. Referenced by add(), Prof::event_objectMove(), and rehash().
|
|
Clears the whole hashtable. Its size remains unchanged. Don't use it - for testing only. |
|
Gets the first item in the hash table for iterating. Returns NULL if the hash table is empty.
Definition at line 139 of file hash.h. Referenced by Prof::event_arenaDelete(), Prof::resumeVM(), and Prof::suspendVM().
|
|
Same action for each item of the hashtable. This method calls the 'f' function (or static method) for each item of the hashtable. The argument of 'f' will be a pointer to item, for which it is called. The 'inout' argument will be used as the second argument of 'f' function. It is used for optional in/out data. If 'f' returns nonzero value, this method quits immediatelly with the same return code as 'f', else when it stops it returns 0.
Definition at line 283 of file hash.h. Referenced by Prof::event_jvmShutDown().
|
|
Searches the hash table for an item corresponing to the specified key. If no item is found, NULL is returned.
Definition at line 254 of file hash.h. Referenced by Prof::event_jniGlobalrefAlloc(), Prof::event_jniGlobalrefFree(), Prof::event_jniWeakGlobalrefAlloc(), Prof::event_jniWeakGlobalrefFree(), Prof::event_objectFree(), Prof::event_objectMove(), Prof::getAllocObject(), Prof::getAllocObjectMethod(), Prof::getAllocObjectTrace(), Prof::getAllocThreadMethod(), Prof::getAllocThreadObject(), Prof::getAllocThreadObjectMethod(), Prof::getAllocThreadObjectTrace(), Prof::getAllocThreadTrace(), Prof::getAllocTrace(), Prof::getClass(), Prof::getCpuThreadMethod(), Prof::getCpuThreadTrace(), Prof::getCpuTrace(), Prof::getMethod(), Prof::getMonThreadMethod(), Prof::getMonThreadTrace(), Prof::getMonTrace(), and Prof::getThread().
|
|
Converts argument to an index to the hash table. Used in conjunction with hash function. Robert Jenkins' 32-bit mix function is used for hashing.
Definition at line 306 of file hash.h. Referenced by addNoRehash(), and get().
|
|
Gets next item for iterating. Returns NULL if the end of the hash table was reached.
Definition at line 159 of file hash.h. Referenced by Prof::resumeVM(), and Prof::suspendVM().
|
|
Rehashing. This method resizes hashtable and rehashes its items.
Definition at line 330 of file hash.h. Referenced by add(), and remove().
|
|
Removes an item from the hash table.
Definition at line 236 of file hash.h. Referenced by Prof::event_arenaDelete(), Prof::event_jniGlobalrefFree(), Prof::event_jniWeakGlobalrefFree(), Prof::event_objectFree(), and Prof::event_objectMove().
|
|
Removes an item from the hash table without rehashing.
Definition at line 217 of file hash.h. Referenced by Prof::event_arenaDelete(), Prof::event_objectFree(), Prof::event_objectMove(), and remove().
|