#include <hashtable.hpp>
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. | |
HashMap & | operator= (const HashMap &reference) |
Copy operator. | |
~HashMap () | |
void | lock_table () |
Locks table (write lock). | |
void | unlock_table () |
Unlocks table (write lock). | |
storeType & | first (long long &position) |
Thread unsafe iterator, returns first element. | |
storeType & | next (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 |
storeType * | content |
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 |
typedef std::pair<KeyT, StoreT> HashMap< KeyT, StoreT, Allocator >::storeType [private] |
enum HashMap::HashMapAllocateStatus [private] |
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).
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.
HashMap< KeyT, StoreT, Allocator >::HashMap | ( | const HashMap< KeyT, StoreT, Allocator > & | reference | ) | [inline] |
Copy construct.
HashMap< KeyT, StoreT, Allocator >::~HashMap | ( | ) | [inline] |
void HashMap< KeyT, StoreT, Allocator >::build | ( | size_t | baseSize = globalBaseSize |
) | [inline, private] |
void HashMap< KeyT, StoreT, Allocator >::build | ( | const HashMap< KeyT, StoreT, Allocator > & | reference | ) | [inline, private] |
void HashMap< KeyT, StoreT, Allocator >::reallocate | ( | ) | [inline, private] |
size_t HashMap< KeyT, StoreT, Allocator >::size | ( | ) | [inline] |
Returns total amount of alocated elements.
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.
HashMap& HashMap< KeyT, StoreT, Allocator >::operator= | ( | const HashMap< KeyT, StoreT, Allocator > & | reference | ) | [inline] |
Copy operator.
void HashMap< KeyT, StoreT, Allocator >::lock_table | ( | ) | [inline] |
Locks table (write lock).
void HashMap< KeyT, StoreT, Allocator >::unlock_table | ( | ) | [inline] |
Unlocks table (write lock).
storeType& HashMap< KeyT, StoreT, Allocator >::first | ( | long long & | position | ) | [inline] |
Thread unsafe iterator, returns first element.
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.
StoreT& HashMap< KeyT, StoreT, Allocator >::operator[] | ( | const KeyT & | key | ) | [inline] |
Semi-safe fetch operator.
void HashMap< KeyT, StoreT, Allocator >::insert | ( | std::pair< KeyT, StoreT > | val | ) | [inline] |
Thread safe insert operation.
void HashMap< KeyT, StoreT, Allocator >::insert | ( | KeyT | key, | |
StoreT | val | |||
) | [inline] |
void HashMap< KeyT, StoreT, Allocator >::erase | ( | const KeyT & | key | ) | [inline] |
Thread safe erase operation.
void HashMap< KeyT, StoreT, Allocator >::unlock | ( | const KeyT & | key | ) | [inline] |
Unlocks selected key. It must be found.
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.
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).
void HashMap< KeyT, StoreT, Allocator >::clear | ( | ) | [inline] |
Erases all elements from table, thread unsafe.
const size_t HashMap< KeyT, StoreT, Allocator >::globalBaseSize = 53 [static, private] |
const size_t HashMap< KeyT, StoreT, Allocator >::upperFillLimit = 50 [static, private] |
size_t(* HashMap< KeyT, StoreT, Allocator >::hash)(size_t maxSize, const KeyT &val) [private] |
size_t(* HashMap< KeyT, StoreT, Allocator >::hash2)(size_t maxSize, const KeyT &val) [private] |
int* HashMap< KeyT, StoreT, Allocator >::refC [private] |
std::deque<HashMap<KeyT, StoreT, Allocator>*>* HashMap< KeyT, StoreT, Allocator >::ref [private] |
Allocator HashMap< KeyT, StoreT, Allocator >::alloc [private] |
storeType* HashMap< KeyT, StoreT, Allocator >::content [private] |
size_t HashMap< KeyT, StoreT, Allocator >::contentSize [private] |
size_t HashMap< KeyT, StoreT, Allocator >::allocated [private] |
unsigned char* HashMap< KeyT, StoreT, Allocator >::allocateStatus [private] |
int HashMap< KeyT, StoreT, Allocator >::sizeIndex [private] |
shared_mutex HashMap< KeyT, StoreT, Allocator >::hashTableLock |
shared_mutex* HashMap< KeyT, StoreT, Allocator >::hashElementLock |
mutex HashMap< KeyT, StoreT, Allocator >::checkMutex |
mutex* HashMap< KeyT, StoreT, Allocator >::hashElementMutex |