HashMap< KeyT, StoreT, Allocator > Class Template Reference

#include <hashtable.hpp>

List of all members.

Public Member Functions

 HashMap (size_t(*hashFunction)(size_t maxSize, const KeyT &val))
 Create using two same hash functions. This is bad idea - field '0' will be unused (as second hashFunction must always return value > 0).
 HashMap (size_t(*hashFunction)(size_t maxSize, const KeyT &val), size_t(*hashFunction2)(size_t maxSize, const KeyT &val))
 Create using hash functions. Second function must return value between 1 and maxSize.
 HashMap (const HashMap &reference)
 Copy construct.
size_t size ()
 Returns total amount of alocated elements.
void forward_allocate (size_t to_be_filled)
 Resizes table so that to_be_filled should fill. This is thread-unsafe and should be used only in startup.
HashMapoperator= (const HashMap &reference)
 Copy operator.
 ~HashMap ()
void lock_table ()
 Locks table (write lock).
void unlock_table ()
 Unlocks table (write lock).
storeTypefirst (long long &position)
 Thread unsafe iterator, returns first element.
storeTypenext (long long &position)
 Thread unsafe iterator, returns next element. On last element, position is set to -1 and [0] is returned. It might not exist, so do not use it.
StoreT & operator[] (const KeyT &key)
 Semi-safe fetch operator.
void insert (std::pair< KeyT, StoreT > val)
 Thread safe insert operation.
void insert (KeyT key, StoreT val)
void erase (const KeyT &key)
 Thread safe erase operation.
void unlock (const KeyT &key)
 Unlocks selected key. It must be found.
StoreT * find_lock (const KeyT &key)
 Finds element, returns pointer to it (or zero if not found). If found, locks database on this key. Use unlock() to unlock it.
StoreT * find (const KeyT &key)
 Same as find_lock(), but thread unsafe (table is not locked after element is returned).
void clear ()
 Erases all elements from table, thread unsafe.

Public Attributes

shared_mutex hashTableLock
shared_mutex * hashElementLock
mutex checkMutex
mutex * hashElementMutex

Private Types

enum  HashMapAllocateStatus { HashMapAllocateStatus_free = 0, HashMapAllocateStatus_deleted = 1, HashMapAllocateStatus_used = 2 }
typedef std::pair< KeyT, StoreT > storeType

Private Member Functions

void build (size_t baseSize=globalBaseSize)
void build (const HashMap &reference)
void reallocate ()

Private Attributes

size_t(* hash )(size_t maxSize, const KeyT &val)
size_t(* hash2 )(size_t maxSize, const KeyT &val)
int * refC
std::deque< HashMap< KeyT,
StoreT, Allocator > * > * 
ref
Allocator alloc
storeTypecontent
size_t contentSize
size_t allocated
unsigned char * allocateStatus
int sizeIndex

Static Private Attributes

static const size_t globalBaseSize = 53
static const size_t upperFillLimit = 50

template<class KeyT, class StoreT, class Allocator>
class HashMap< KeyT, StoreT, Allocator >


Member Typedef Documentation

template<class KeyT, class StoreT, class Allocator>
typedef std::pair<KeyT, StoreT> HashMap< KeyT, StoreT, Allocator >::storeType [private]


Member Enumeration Documentation

template<class KeyT, class StoreT, class Allocator>
enum HashMap::HashMapAllocateStatus [private]

Enumerator:
HashMapAllocateStatus_free 
HashMapAllocateStatus_deleted 
HashMapAllocateStatus_used 


Constructor & Destructor Documentation

template<class KeyT, class StoreT, class Allocator>
HashMap< KeyT, StoreT, Allocator >::HashMap ( size_t(*)(size_t maxSize, const KeyT &val)  hashFunction  )  [inline]

Create using two same hash functions. This is bad idea - field '0' will be unused (as second hashFunction must always return value > 0).

template<class KeyT, class StoreT, class Allocator>
HashMap< KeyT, StoreT, Allocator >::HashMap ( size_t(*)(size_t maxSize, const KeyT &val)  hashFunction,
size_t(*)(size_t maxSize, const KeyT &val)  hashFunction2 
) [inline]

Create using hash functions. Second function must return value between 1 and maxSize.

template<class KeyT, class StoreT, class Allocator>
HashMap< KeyT, StoreT, Allocator >::HashMap ( const HashMap< KeyT, StoreT, Allocator > &  reference  )  [inline]

Copy construct.

template<class KeyT, class StoreT, class Allocator>
HashMap< KeyT, StoreT, Allocator >::~HashMap (  )  [inline]


Member Function Documentation

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::build ( size_t  baseSize = globalBaseSize  )  [inline, private]

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::build ( const HashMap< KeyT, StoreT, Allocator > &  reference  )  [inline, private]

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::reallocate (  )  [inline, private]

template<class KeyT, class StoreT, class Allocator>
size_t HashMap< KeyT, StoreT, Allocator >::size (  )  [inline]

Returns total amount of alocated elements.

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::forward_allocate ( size_t  to_be_filled  )  [inline]

Resizes table so that to_be_filled should fill. This is thread-unsafe and should be used only in startup.

template<class KeyT, class StoreT, class Allocator>
HashMap& HashMap< KeyT, StoreT, Allocator >::operator= ( const HashMap< KeyT, StoreT, Allocator > &  reference  )  [inline]

Copy operator.

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::lock_table (  )  [inline]

Locks table (write lock).

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::unlock_table (  )  [inline]

Unlocks table (write lock).

template<class KeyT, class StoreT, class Allocator>
storeType& HashMap< KeyT, StoreT, Allocator >::first ( long long &  position  )  [inline]

Thread unsafe iterator, returns first element.

template<class KeyT, class StoreT, class Allocator>
storeType& HashMap< KeyT, StoreT, Allocator >::next ( long long &  position  )  [inline]

Thread unsafe iterator, returns next element. On last element, position is set to -1 and [0] is returned. It might not exist, so do not use it.

template<class KeyT, class StoreT, class Allocator>
StoreT& HashMap< KeyT, StoreT, Allocator >::operator[] ( const KeyT &  key  )  [inline]

Semi-safe fetch operator.

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::insert ( std::pair< KeyT, StoreT >  val  )  [inline]

Thread safe insert operation.

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::insert ( KeyT  key,
StoreT  val 
) [inline]

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::erase ( const KeyT &  key  )  [inline]

Thread safe erase operation.

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::unlock ( const KeyT &  key  )  [inline]

Unlocks selected key. It must be found.

template<class KeyT, class StoreT, class Allocator>
StoreT* HashMap< KeyT, StoreT, Allocator >::find_lock ( const KeyT &  key  )  [inline]

Finds element, returns pointer to it (or zero if not found). If found, locks database on this key. Use unlock() to unlock it.

template<class KeyT, class StoreT, class Allocator>
StoreT* HashMap< KeyT, StoreT, Allocator >::find ( const KeyT &  key  )  [inline]

Same as find_lock(), but thread unsafe (table is not locked after element is returned).

template<class KeyT, class StoreT, class Allocator>
void HashMap< KeyT, StoreT, Allocator >::clear (  )  [inline]

Erases all elements from table, thread unsafe.


Member Data Documentation

template<class KeyT, class StoreT, class Allocator>
const size_t HashMap< KeyT, StoreT, Allocator >::globalBaseSize = 53 [static, private]

template<class KeyT, class StoreT, class Allocator>
const size_t HashMap< KeyT, StoreT, Allocator >::upperFillLimit = 50 [static, private]

template<class KeyT, class StoreT, class Allocator>
size_t(* HashMap< KeyT, StoreT, Allocator >::hash)(size_t maxSize, const KeyT &val) [private]

template<class KeyT, class StoreT, class Allocator>
size_t(* HashMap< KeyT, StoreT, Allocator >::hash2)(size_t maxSize, const KeyT &val) [private]

template<class KeyT, class StoreT, class Allocator>
int* HashMap< KeyT, StoreT, Allocator >::refC [private]

template<class KeyT, class StoreT, class Allocator>
std::deque<HashMap<KeyT, StoreT, Allocator>*>* HashMap< KeyT, StoreT, Allocator >::ref [private]

template<class KeyT, class StoreT, class Allocator>
Allocator HashMap< KeyT, StoreT, Allocator >::alloc [private]

template<class KeyT, class StoreT, class Allocator>
storeType* HashMap< KeyT, StoreT, Allocator >::content [private]

template<class KeyT, class StoreT, class Allocator>
size_t HashMap< KeyT, StoreT, Allocator >::contentSize [private]

template<class KeyT, class StoreT, class Allocator>
size_t HashMap< KeyT, StoreT, Allocator >::allocated [private]

template<class KeyT, class StoreT, class Allocator>
unsigned char* HashMap< KeyT, StoreT, Allocator >::allocateStatus [private]

template<class KeyT, class StoreT, class Allocator>
int HashMap< KeyT, StoreT, Allocator >::sizeIndex [private]

template<class KeyT, class StoreT, class Allocator>
shared_mutex HashMap< KeyT, StoreT, Allocator >::hashTableLock

template<class KeyT, class StoreT, class Allocator>
shared_mutex* HashMap< KeyT, StoreT, Allocator >::hashElementLock

template<class KeyT, class StoreT, class Allocator>
mutex HashMap< KeyT, StoreT, Allocator >::checkMutex

template<class KeyT, class StoreT, class Allocator>
mutex* HashMap< KeyT, StoreT, Allocator >::hashElementMutex


The documentation for this class was generated from the following file:

Generated on Thu Oct 22 16:31:08 2009 for Limit server by  doxygen 1.5.6