Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Hash Class Template Reference

Hash table template. More...

#include <hash.h>

List of all members.

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.


Detailed Description

template<class T, class K, class L>
class Hash< T, K, L >

Hash table template.

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.

Parameters:
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.)
See also:
List, ListItem
Author:
Marek Przeczek, Petr Luner

Definition at line 81 of file hash.h.


Member Enumeration Documentation

template<class T, class K, class L>
enum Hash::e [private]
 

constants.

Enumeration values:
HASH_LIST_LIMIT  hashtable limit.

Definition at line 84 of file hash.h.


Member Function Documentation

template<class T, class K, class L>
T* Hash< T, K, L >::add T *    item [inline]
 

Adds an item to the hash table.

Parameters:
item  pointer to an item
Returns:
pointer to the inserted item
See also:
addNoRehash(), remove(), removeNoRehash()

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().

template<class T, class K, class L>
T* Hash< T, K, L >::addNoRehash T *    item [inline]
 

Adds an item to the hash table without rehashing.

Parameters:
item  pointer to an item
Returns:
pointer to the inserted item
See also:
add(), remove(), removeNoRehash()

Definition at line 180 of file hash.h.

Referenced by add(), Prof::event_objectMove(), and rehash().

template<class T, class K, class L>
void Hash< T, K, L >::clear   [inline]
 

Clears the whole hashtable.

Its size remains unchanged. Don't use it - for testing only.

Definition at line 126 of file hash.h.

template<class T, class K, class L>
T* Hash< T, K, L >::first   [inline]
 

Gets the first item in the hash table for iterating.

Returns NULL if the hash table is empty.

Returns:
pointer to an item or NULL
See also:
next()

Definition at line 139 of file hash.h.

Referenced by Prof::event_arenaDelete(), Prof::resumeVM(), and Prof::suspendVM().

template<class T, class K, class L>
int Hash< T, K, L >::forEach int(*    f)(T *, void **),
void **    inout
[inline]
 

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.

Parameters:
f  pointer to function
inout  the second argument of 'f' function
Returns:
value
See also:
List

Definition at line 283 of file hash.h.

Referenced by Prof::event_jvmShutDown().

template<class T, class K, class L>
T* Hash< T, K, L >::get const K &    key [inline]
 

Searches the hash table for an item corresponing to the specified key.

If no item is found, NULL is returned.

Parameters:
key  key to search for
Returns:
pointer to the found item

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().

template<class T, class K, class L>
unsigned int Hash< T, K, L >::makeIndex int    x [inline, private]
 

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.

Parameters:
x  typically result of a hash function
Returns:
hash table index

Definition at line 306 of file hash.h.

Referenced by addNoRehash(), and get().

template<class T, class K, class L>
T* Hash< T, K, L >::next T *    item [inline]
 

Gets next item for iterating.

Returns NULL if the end of the hash table was reached.

Parameters:
item  pointer to an item
Returns:
pointer to the next item or NULL
See also:
first()

Definition at line 159 of file hash.h.

Referenced by Prof::resumeVM(), and Prof::suspendVM().

template<class T, class K, class L>
void Hash< T, K, L >::rehash unsigned int    sz [inline, private]
 

Rehashing.

This method resizes hashtable and rehashes its items.

Parameters:
sz  new size of hashtable

Definition at line 330 of file hash.h.

Referenced by add(), and remove().

template<class T, class K, class L>
T* Hash< T, K, L >::remove T *    item [inline]
 

Removes an item from the hash table.

Parameters:
item  pointer to an item
Returns:
pointer to the removed item
See also:
add(), addNoRehash(), removeNoRehash()

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().

template<class T, class K, class L>
T* Hash< T, K, L >::removeNoRehash T *    item [inline]
 

Removes an item from the hash table without rehashing.

Parameters:
item  pointer to an item
Returns:
pointer to the removed item
See also:
remove(), add(), addNoRehash()

Definition at line 217 of file hash.h.

Referenced by Prof::event_arenaDelete(), Prof::event_objectFree(), Prof::event_objectMove(), and remove().


The documentation for this class was generated from the following file:
Generated on Mon Jan 28 14:53:28 2002 for Java Profiler Dynamic Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001