PHashTable Class Reference

The hash table class is the basis for implementing the PSet and PDictionary classes. More...

#include <dict.h>

Inheritance diagram for PHashTable:

PCollection PContainer PObject PAbstractDictionary PAbstractSet PDictionary< K, D > POrdinalDictionary< K > PStringDictionary< K > PSet< T > PStringToOrdinal POrdinalToString PStringToString PStringSet PMIMEInfo List of all members.

Public Types

typedef PHashTableElement Element
typedef PHashTableInfo Table

Public Member Functions

Construction
 PHashTable ()
 Create a new, empty, hash table.
Overrides from class PObject
virtual Comparison Compare (const PObject &obj) const
 Get the relative rank of the two hash tables.
Overrides from class PContainer
virtual PBoolean SetSize (PINDEX newSize)
 This function is meaningless for hash table.
New functions for class
PINLINE PBoolean AbstractContains (const PObject &key) const
 Determine if the value of the object is contained in the hash table.
virtual const PObjectAbstractGetKeyAt (PINDEX index) const
 Get the key in the hash table at the ordinal index position.
virtual PObjectAbstractGetDataAt (PINDEX index) const
 Get the data in the hash table at the ordinal index position.

Public Attributes

PHashTableInfo * hashTable

Detailed Description

The hash table class is the basis for implementing the PSet and PDictionary classes.

The hash table allows for very fast searches for an object based on a "hash function". This function yields an index into an array which is directly looked up to locate the object. When two key values have the same hash function value, then a linear search of a linked list is made to locate the object. Thus the efficiency of the hash table is highly dependent on the quality of the hash function for the data being used as keys.


Member Typedef Documentation

typedef PHashTableElement PHashTable::Element

typedef PHashTableInfo PHashTable::Table


Constructor & Destructor Documentation

PHashTable::PHashTable (  ) 

Create a new, empty, hash table.


Member Function Documentation

PINLINE PBoolean PHashTable::AbstractContains ( const PObject key  )  const

Determine if the value of the object is contained in the hash table.

The object values are compared, not the pointers. So the objects in the collection must correctly implement the PObject::Compare() function. The hash table is used to locate the entry.

Returns:
true if the object value is in the set.
Parameters:
key  Key to look for in the set.

virtual PObject& PHashTable::AbstractGetDataAt ( PINDEX  index  )  const [virtual]

Get the data in the hash table at the ordinal index position.

The ordinal position in the hash table is determined by the hash values of the keys and the order of insertion.

The last key/data pair is remembered by the class so that subseqent access is very fast.

This function is primarily used by the descendent template classes, or macro, with the appropriate type conversion.

Returns:
reference to key at the index position.
Parameters:
index  Ordinal position in the hash table.

virtual const PObject& PHashTable::AbstractGetKeyAt ( PINDEX  index  )  const [virtual]

Get the key in the hash table at the ordinal index position.

The ordinal position in the hash table is determined by the hash values of the keys and the order of insertion.

The last key/data pair is remembered by the class so that subseqent access is very fast.

This function is primarily used by the descendent template classes, or macro, with the appropriate type conversion.

Returns:
reference to key at the index position.
Parameters:
index  Ordinal position in the hash table.

virtual Comparison PHashTable::Compare ( const PObject obj  )  const [virtual]

Get the relative rank of the two hash tables.

Actally ranking hash tables is really meaningless, so only equality is returned by the comparison. Equality is only achieved if the two instances reference the same hash table.

Returns:
comparison of the two objects, EqualTo if the same reference and GreaterThan if not.
Parameters:
obj  Other PHashTable to compare against.

Reimplemented from PObject.

virtual PBoolean PHashTable::SetSize ( PINDEX  newSize  )  [virtual]

This function is meaningless for hash table.

The size of the collection is determined by the addition and removal of objects. The size cannot be set in any other way.

Returns:
Always true.
Parameters:
newSize  New size for the hash table, this is ignored.

Implements PContainer.


Member Data Documentation

PHashTableInfo* PHashTable::hashTable


The documentation for this class was generated from the following file:
Generated on Fri Oct 14 01:44:11 2011 for PTLib by  doxygen 1.4.7