PSet
and PDictionary
classes.
More...
#include <dict.h>
Inheritance diagram for PHashTable:
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 PObject & | AbstractGetKeyAt (PINDEX index) const |
Get the key in the hash table at the ordinal index position. | |
virtual PObject & | AbstractGetDataAt (PINDEX index) const |
Get the data in the hash table at the ordinal index position. | |
Public Attributes | |
PHashTableInfo * | hashTable |
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.
typedef PHashTableElement PHashTable::Element |
typedef PHashTableInfo PHashTable::Table |
PHashTable::PHashTable | ( | ) |
Create a new, empty, hash table.
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.
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.
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.
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.
EqualTo
if the same reference and GreaterThan
if not. 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.
newSize | New size for the hash table, this is ignored. |
Implements PContainer.
PHashTableInfo* PHashTable::hashTable |