CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

csHash< T, K, KeyHandler > Class Template Reference

A generic hash table class, which grows dynamically and whose buckets are unsorted arrays. More...

#include <hash.h>

Inheritance diagram for csHash< T, K, KeyHandler >:

csHashReversible< T, K, KeyHandler, ReverseKeyHandler > List of all members.

Public Methods

 csHash (int size=257, int grow_rate=64, int max_size=20000)
 Construct a hash table with an array of the given size, which for optimisation reasons should be a prime number.

 csHash (const csHash< T > &o)
 Copy constructor.

void Put (const K &key, const T &value)
 Add an element to the hash table.

csArray< T > GetAll (const K &key) const
 Get all the elements with the given key, or empty if there are none.

void PutFirst (const K &key, const T &value)
 Add an element to the hash table, overwriting if the key already exists.

bool In (const K &key) const
 Returns whether at least one element matches the given key.

const T * GetElementPointer (const K &key) const
 Get a pointer to the first element matching the given key, or 0 if there is 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 & Get (const K &key, const T &fallback) const
 Get the first element matching the given key, or fallback if there is none.

T & Get (const K &key, T &fallback)
 Get the first element matching the given key, or fallback if there is none.

void DeleteAll ()
 Delete all the elements.

bool DeleteAll (const K &key)
 Delete all the elements matching the given key.

bool Delete (const K &key, const T &value)
 Delete all the elements matching the given key and value.

int GetSize () const
 Get the number of elements in the hash.

void DeleteElement (GlobalIterator &iterator)
 Delete the element pointed by the iterator.

Iterator GetIterator (const K &key) const
 Return an iterator for the hash, to iterate only over the elements with the given key.

GlobalIterator GetIterator () const
 Return an iterator for the hash, to iterate over all elements.


Detailed Description

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
class csHash< T, K, KeyHandler >

A generic hash table class, which grows dynamically and whose buckets are unsorted arrays.

Definition at line 75 of file hash.h.


Constructor & Destructor Documentation

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
csHash< T, K, KeyHandler >::csHash (  int    size = 257,
int    grow_rate = 64,
int    max_size = 20000
)  [inline]
 

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/

Definition at line 148 of file hash.h.

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
csHash< T, K, KeyHandler >::csHash (  const csHash< T > &    o )  [inline]
 

Copy constructor.

Definition at line 156 of file hash.h.


Member Function Documentation

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
bool csHash< T, K, KeyHandler >::Delete (  const K &    key,
const T &    value
)  [inline]
 

Delete all the elements matching the given key and value.

Definition at line 325 of file hash.h.

Referenced by csSet< T, KeyHandler >::Delete().

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
bool csHash< T, K, KeyHandler >::DeleteAll (  const K &    key )  [inline]
 

Delete all the elements matching the given key.

Definition at line 309 of file hash.h.

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
void csHash< T, K, KeyHandler >::DeleteAll (    )  [inline]
 

Delete all the elements.

Definition at line 299 of file hash.h.

Referenced by csSet< T, KeyHandler >::DeleteAll().

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
void csHash< T, K, KeyHandler >::DeleteElement (  GlobalIterator &    iterator )  [inline]
 

Delete the element pointed by the iterator.

This is safe for this iterator, not for the others.

Definition at line 512 of file hash.h.

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
T& csHash< T, K, KeyHandler >::Get (  const K &    key,
T &    fallback
)  [inline]
 

Get the first element matching the given key, or fallback if there is none.

Definition at line 283 of file hash.h.

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
const T& csHash< T, K, KeyHandler >::Get (  const K &    key,
const T &    fallback
)  const [inline]
 

Get the first element matching the given key, or fallback if there is none.

Definition at line 264 of file hash.h.

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
csArray<T> csHash< T, K, KeyHandler >::GetAll (  const K &    key )  const [inline]
 

Get all the elements with the given key, or empty if there are none.

Definition at line 172 of file hash.h.

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
T* csHash< T, K, KeyHandler >::GetElementPointer (  const K &    key )  [inline]
 

Get a pointer to the first element matching the given key, or 0 if there is none.

Definition at line 245 of file hash.h.

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
const T* csHash< T, K, KeyHandler >::GetElementPointer (  const K &    key )  const [inline]
 

Get a pointer to the first element matching the given key, or 0 if there is none.

Definition at line 226 of file hash.h.

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
GlobalIterator csHash< T, K, KeyHandler >::GetIterator (    )  const [inline]
 

Return an iterator for the hash, to iterate over all elements.

Modifying the hash (except with DeleteElement) while you have open iterators will cause undefined behaviour.

Definition at line 536 of file hash.h.

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
Iterator csHash< T, K, KeyHandler >::GetIterator (  const K &    key )  const [inline]
 

Return an iterator for the hash, to iterate only over the elements with the given key.

Modifying the hash (except with DeleteElement) while you have open iterators will cause undefined behaviour.

Definition at line 526 of file hash.h.

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
int csHash< T, K, KeyHandler >::GetSize (    )  const [inline]
 

Get the number of elements in the hash.

Definition at line 342 of file hash.h.

Referenced by csSet< T, KeyHandler >::GetSize().

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
bool csHash< T, K, KeyHandler >::In (  const K &    key )  const [inline]
 

Returns whether at least one element matches the given key.

Definition at line 210 of file hash.h.

Referenced by csSet< T, KeyHandler >::In().

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
void csHash< T, K, KeyHandler >::Put (  const K &    key,
const T &    value
)  [inline]
 

Add an element to the hash table.

Reimplemented in csHashReversible< T, K, KeyHandler, ReverseKeyHandler >.

Definition at line 161 of file hash.h.

Referenced by csSet< T, KeyHandler >::AddNoTest(), and csHashReversible< T, K, KeyHandler, ReverseKeyHandler >::Put().

template<class T, class K = unsigned int, class KeyHandler = csIntegralHashKeyHandler<K>>
void csHash< T, K, KeyHandler >::PutFirst (  const K &    key,
const T &    value
)  [inline]
 

Add an element to the hash table, overwriting if the key already exists.

Definition at line 188 of file hash.h.


The documentation for this class was generated from the following file:
Generated for Crystal Space by doxygen 1.2.18