csHash< T, K > Class Template Reference
[Containers]
A generic hash table class, which grows dynamically and whose buckets are unsorted arrays.
More...
#include <csutil/hash.h>
Inheritance diagram for csHash< T, K >:

Public Member Functions | |
bool | Contains (const K &key) const |
Returns whether at least one element matches the given key. | |
csHash (const csHash< T > &o) | |
Copy constructor. | |
csHash (size_t size=23, size_t grow_rate=5, size_t max_size=20000) | |
Construct a hash table with an array of the given size, which for optimisation reasons should be a prime number. | |
bool | Delete (const K &key, const T &value) |
Delete all the elements matching the given key and value. | |
bool | DeleteAll (const K &key) |
Delete all the elements matching the given key. | |
void | DeleteAll () |
Delete all the elements. | |
void | DeleteElement (GlobalIterator &iterator) |
Delete the element pointed by the iterator. | |
void | Empty () |
Delete all the elements. (Idiomatic alias for DeleteAll().). | |
T & | Get (const K &key, T &fallback) |
Get the first element matching the given key, or fallback if there is none. | |
const T & | Get (const K &key, const T &fallback) const |
Get the first element matching the given key, or fallback if there is none. | |
csArray< T > | GetAll (const K &key) const |
Get all the elements with the given key, or empty if there are none. | |
T * | GetElementPointer (const K &key) |
Get a pointer to the first element matching the given key, or 0 if there is none. | |
const T * | GetElementPointer (const K &key) const |
Get a pointer to the first element matching the given key, or 0 if there is none. | |
GlobalIterator | GetIterator () const |
Return an iterator for the hash, to iterate over all elements. | |
Iterator | GetIterator (const K &key) const |
Return an iterator for the hash, to iterate only over the elements with the given key. | |
size_t | GetSize () const |
Get the number of elements in the hash. | |
bool | In (const K &key) const |
Returns whether at least one element matches the given key. | |
bool | IsEmpty () const |
Return true if the hash is empty. | |
void | Put (const K &key, const T &value) |
Add an element to the hash table. | |
void | PutFirst (const K &key, const T &value) |
Add an element to the hash table, overwriting if the key already exists. | |
void | PutUnique (const K &key, const T &value) |
Add an element to the hash table, overwriting if the key already exists. | |
Protected Attributes | |
csArray< csArray< Element > > | Elements |
size_t | Modulo |
Friends | |
class | GlobalIterator |
class | Iterator |
Classes | |
struct | Element |
class | GlobalIterator |
An iterator class for the hash. More... | |
class | Iterator |
An iterator class for the hash. More... |
Detailed Description
template<class T, class K = unsigned int>
class csHash< T, K >
A generic hash table class, which grows dynamically and whose buckets are unsorted arrays.
The hash value of a key is computed using csHashComputer<>, two keys are compared using csComparator<>. You need to provide appropriate specializations of those templates if you want use non-integral types (other than const char*, csStrKey and csString for which appropriate specializations are already provided) or special hash algorithms.
Definition at line 249 of file hash.h.
Constructor & Destructor Documentation
|
Construct a hash table with an array of the given size, which for optimisation reasons should be a prime number. Grow_rate is the rate at which the hash table grows: Size doubles once there are size/grow_rate collisions. It will not grow after it reaches max_size. Here are a few primes: 7, 11, 19, 29, 59, 79, 101, 127, 151, 199, 251, 307, 401, 503, 809, 1009, 1499, 2003, 3001, 5003, 12263, 25247, 36923, 50119, 70951, 90313, 104707. For a bigger list go to http://www.utm.edu/research/primes/ |
|
Copy constructor.
|
Member Function Documentation
|
Returns whether at least one element matches the given key.
Definition at line 400 of file hash.h. Referenced by csSet< csPtrKey< KnownFont > >::Contains(). |
|
Delete all the elements matching the given key and value.
Definition at line 528 of file hash.h. Referenced by csSet< csPtrKey< KnownFont > >::Delete(). |
|
Delete all the elements matching the given key.
|
|
Delete all the elements.
Definition at line 496 of file hash.h. Referenced by csSet< csPtrKey< KnownFont > >::DeleteAll(). |
|
Delete the element pointed by the iterator. This is safe for this iterator, not for the others. |
|
Delete all the elements. (Idiomatic alias for DeleteAll().).
|
|
Get the first element matching the given key, or
|
|
Get the first element matching the given key, or
Definition at line 461 of file hash.h. Referenced by csHashReversible< T, K >::GetKey(). |
|
Get all the elements with the given key, or empty if there are none.
|
|
Get a pointer to the first element matching the given key, or 0 if there is none.
|
|
Get a pointer to the first element matching the given key, or 0 if there is none.
Definition at line 423 of file hash.h. Referenced by csHashReversible< T, K >::GetKeyPointer(). |
|
Return an iterator for the hash, to iterate over all elements.
|
|
Return an iterator for the hash, to iterate only over the elements with the given key.
|
|
Get the number of elements in the hash.
Definition at line 548 of file hash.h. Referenced by csSet< csPtrKey< KnownFont > >::GetSize(). |
|
Returns whether at least one element matches the given key.
|
|
Return true if the hash is empty.
|
|
Add an element to the hash table.
Reimplemented in csHashReversible< T, K >. Definition at line 342 of file hash.h. Referenced by csSet< csPtrKey< KnownFont > >::AddNoTest(), and csHashReversible< T, K >::Put(). |
|
Add an element to the hash table, overwriting if the key already exists.
|
|
Add an element to the hash table, overwriting if the key already exists.
|
The documentation for this class was generated from the following file:
- csutil/hash.h
Generated for Crystal Space by doxygen 1.4.6