MAUtil::HashMap< Key, Value > Class Template Reference
#include <MAUtil/HashMap.h>
List of all members.
Detailed Description
template<class Key, class Value>
class MAUtil::HashMap< Key, Value >
Thin template HashMap.
The HashMap is a data storage mechanism that stores unique keys, and a value associated with each key.
It has very fast insert, erase and lookup operations, assuming a good hash function is being used. For a perfect hash function (which generally doesn't exist), lookups and erases take constant time, while inserts run in constant time amortized over O(n).
It has an Iterator, which allows you to access all elements. The HashMap is not sorted. For each iteration, you will get an undefined, semi-random order of elements.
This particular implementation is built on top of kazlib's hash table system, which makes it quite small, even when used with multiple data types.
Member Typedef Documentation
Constructor & Destructor Documentation
|
Constructs an empty HashMap. - Parameters:
-
| hf | The hash function. |
| cf | The compare function. See Compare. |
| init_bits | The intial size of the hash table is 2 to the power of this number. While the table grows and shrinks dynamically, it is possible to optimize if you're doing a known number of insertions directly after constructing the HashMap. |
|
|
Constructs a copy of another HashMap. All elements are also copied.
|
|
The destructor deletes all elements.
|
Member Function Documentation
|
Inserts a new key into the HashMap.
Returns a Pair. The Pair's second element is true if the value was indeed inserted. The Pair's first element is an Iterator that points to the element in the HashMap.
An element which compares equal to the new one may already be present in the HashMap; in that case, this operation does nothing, and the Iterator returned will point to the old element. |
|
Searches the HashMap for a specified Key. The returned Iterator points to the element matching the Key if one was found, or to HashMap::end() if not. |
template<class Key, class Value> |
bool MAUtil::HashMap< Key, Value >::erase |
( |
const Key & |
|
) |
|
|
|
Deletes an element, matching the specified Key, from the HashMap. Returns true if an element was erased, or false if there was no element matching the Key. |
|
Deletes an element, pointed to by the specified Iterator. The Iterator is invalidated, so if you want to continue iterating through the HashMap, you must use a different Iterator instance. - Warning:
- If the Iterator is bound to a different HashMap, or if it points to end(), the system will crash.
|
|
Returns the number of elements in the HashMap. |
template<class Key, class Value> |
void MAUtil::HashMap< Key, Value >::clear |
( |
|
) |
|
|
|
Returns an Iterator pointing to a place beyond the last element of the HashMap. This Iterator is often used to determine when another Iterator has reached its end. |
template<class Key, class Value> |
Value & MAUtil::HashMap< Key, Value >::operator[] |
( |
const Key & |
|
) |
|
|
|
The square bracket operator returns a reference to the Value corresponding to the specified Key.
If the Key doesn't yet exist in the HashMap, it will be inserted with a default Value.
There is no const variant of this function, because each call might potentially modify the HashMap by inserting a new key. Use find() if you have a const HashMap. |
template<class Key, class Value> |
static hnode_t* MAUtil::HashMap< Key, Value >::alloc |
( |
void * |
|
) |
[inline, static, protected] |
|
template<class Key, class Value> |
static void MAUtil::HashMap< Key, Value >::free |
( |
hnode_t * |
node, |
|
|
void * |
|
|
) |
[inline, static, protected] |
|
template<class Key, class Value> |
void MAUtil::HashMap< Key, Value >::init |
( |
|
) |
[protected] |
|
Member Data Documentation
Generated on Sat Feb 13 00:15:39 2010 for MoSync 2 beta 1 by
1.4.6-NO