-
template
class
PortableHashtable<class KeyType, class ValueType>
(Return to index)
-
This is a handy templated Hashtable class, similar to Java's java.util.Hashtable.
Type:
Include file:
../../hashtable/PortableHashtable.h
Synopsis:
- Public:
- void
Clear
()
;
-
- bool
Contains
(const ValueType& value) const
;
-
- bool
ContainsKey
( const KeyType& key) const
;
-
- bool
Get
(const KeyType& key, ValueType& setValue) const
;
-
- PortableHashtableIterator<KeyType,ValueType>
GetIterator
() const
;
-
- bool
IsEmpty
() const
;
-
-
PortableHashtable
(uint32(*func)(const KeyType& key), uint32 initialCapacity = 13, float loadFactor = 0.5f)
;
-
- void
Put
(const KeyType& key, const ValueType& value)
;
-
- bool
Put
(const KeyType& key, const ValueType& value, ValueType & setPreviousValue)
;
-
- bool
Remove
(const KeyType& key)
;
-
- bool
Remove
(const KeyType& key, ValueType & setRemovedValue)
;
-
- void
SetCompareFunction
(bool(*func)(const KeyType& key1, const KeyType& key2))
;
-
- void
SetHashFunction
(uint32(*func)(const KeyType& key))
;
-
- uint32
Size
() const
;
-
- virtual
~PortableHashtable
()
;
-
- Friends:
- friend class
PortableHashtableIterator, ValueType
;
-
Public methods:
- public void
Clear ()
Removes all mappings from the hash table.
- public bool
Contains (const ValueType& value) const
Returns true iff the table contains a mapping with the given value. (O(n) search time)
- public bool
ContainsKey ( const KeyType& key) const
Returns true iff the table contains a mapping with the given key. (O(1) search time)
- public bool
Get (const KeyType& key, ValueType& setValue) const
If the given (key) is in the table, copies the associated value into (setValue)
and returns true. Otherwise returns false.
- public PortableHashtableIterator<KeyType,ValueType>
GetIterator () const
Returns an iterator object that can be used to enumerate the items in the hash table.
- public bool
IsEmpty () const
Returns true iff the table is empty
- public
PortableHashtable (uint32(*func)(const KeyType& key), uint32 initialCapacity = 13, float loadFactor = 0.5f)
(func) specified a function that returns an integer hashcode for a given key object.
(initialCapacity) specifies the number of slots to initially pre-allocate. Defaults to 13.
(loadFactor) specifies how densely populated the table must be before it is re-hashed. Defaults to 0.5 (i.e. 50%)
- public void
Put (const KeyType& key, const ValueType& value)
Places the given (key, value) mapping into the table. Any previous entry with
a key of (key) will be replaced.
- public bool
Put (const KeyType& key, const ValueType& value, ValueType & setPreviousValue)
Modifiers
=========
Places the given (key, value) mapping into the table. Any previous entry with
a key of (key) will be replaced. If there was a previously existing mapping
with the given (key), its value will be copied into (setPreviousValue) and this
method will return true. Otherwise, this method will return false.
- public bool
Remove (const KeyType& key)
Removes the mapping with the given (key). Returns true on success, false on
failure (i.e. no mapping with the given (key) was found)
- public bool
Remove (const KeyType& key, ValueType & setRemovedValue)
Removes the mapping with the given (key) and places its value into (setRemovedValue).
Returns true on success, false on failure (i.e. no mapping with the given (key) was found).
- public void
SetCompareFunction (bool(*func)(const KeyType& key1, const KeyType& key2))
You can call this to set a function to use to compare keys. By default, the
'==' operator is used, but for some key types (e.g. const char *'s) '==' is not
useful.
- public void
SetHashFunction (uint32(*func)(const KeyType& key))
You can call this to change the hash function that is used to generate integer
hashing values from the key items.
- public uint32
Size () const
Inspectors
==========
Returns the number of items in the table
- public virtual
~PortableHashtable ()
Friend methods: