![]()
|
TOP --> libjdl
This class provides a simple hash dictionary. It can be used to store data that is keyed by a string value. The following example shows how this class is used:
#include "jdlhashtable.h" int main(int argc,char* argv[]) { CJdlHashTable tbl; // Populate the list tbl.Insert("FOO",(void*)10); tbl.Insert("BAR",(void*)30); tbl.Insert("SPAM",(void*)5); // Contains? if(tbl.Contains("FOO")) { int i = int(tbl.Get("FOO")); } return 0; }
public CJdlHashTable ( ) ; Default constructor. This sets the hash table list size to 10357. If you expect to have more than about 5000 items, you should increase the table size to the nearest prime that is larger than twice the number of expected items. public CJdlHashTable ( uint size ) ; Constructor.
public ~ CJdlHashTable ( ) ; Destructor. protected CJdlVector < CJdlRedBlackTree > m_ListOfRbTrees The hash table is a list of Red-black trees. This guarantees that worst case performance is k + O(n (log (n) ) ). protected uint m_NumItems Number of items in the hash table. public void Resize ( uint size ) ; Resize the hash table. This is a very costly operation because each entry has to be rehashed. Don't do it if you can possibly avoid it.
public void Insert ( const char * key , void * value ) ; Insert a key/value pair into the hash table. Duplicate keys are allowed but the retrieval order is not defined.
public void Put ( const char * , void * ) ; Insert a record into the hash table. This method is identical to Insert(). public void * Get ( const char * key ) ; Retrieve a value from the hash table. If the key does not exist, 0 is returned. This method should be used in conjunction with Contains() as follows: if(hash.Contains("MYKEY")) { int val = (int) hash.Get("MYKEY"); }
public const char * GetKey ( const char * key ) ; Retrieve the key address from the hash table. If the key does not exist, 0 is returned. This method should be used in conjunction with Contains() as follows: if(hash.Contains("MYKEY")) { const char* key = hash.GetKey("MYKEY"); }
public void Remove ( const char * ) ; Remove an entry from the hash table. If the specified entry does not exist, nothing is changed.
public bool Contains ( const char * key ) ; Is this record in the hash table?
public void Clear ( ) ; Clear the hash table. public virtual uint Hash ( const char * ) const ; Hash function based on hashpjw on page 436 of the Aho, Sethi and Ullman Compiler book.
public void Copy ( const CJdlHashTable & tbl ) ; Copy one hash table to another.
public uint Size ( ) const ;
public uint GetNumItems ( ) const ;
public CJdlHashTable & operator = ( const CJdlHashTable & tbl ) ; Copy operator.
This documentation was generated automatically by the ccdoc tool (version 0.7a).
Click here to return to the top of the page. |