ucx
UAP Common Extensions
|
Hash map implementation. More...
#include "map.h"
Go to the source code of this file.
Data Structures | |
struct | cx_hash_map_s |
Internal structure for a hash map. More... | |
Macros | |
#define | cxHashMapCreateSimple(itemsize) cxHashMapCreate(cxDefaultAllocator, itemsize, 0) |
Creates a new hash map with a default number of buckets. | |
Functions | |
CxMap * | cxHashMapCreate (CxAllocator const *allocator, size_t itemsize, size_t buckets) |
Creates a new hash map with the specified number of buckets. | |
int | cxMapRehash (CxMap *map) |
Increases the number of buckets, if necessary. | |
Hash map implementation.
#define cxHashMapCreateSimple | ( | itemsize | ) | cxHashMapCreate(cxDefaultAllocator, itemsize, 0) |
Creates a new hash map with a default number of buckets.
If item_size
is CX_STORE_POINTERS, the created map will be created as if cxMapStorePointers() was called immediately after creation.
index==size
.itemsize | the size of one element |
CxMap * cxHashMapCreate | ( | CxAllocator const * | allocator, |
size_t | itemsize, | ||
size_t | buckets | ||
) |
Creates a new hash map with the specified number of buckets.
If buckets
is zero, an implementation defined default will be used.
If item_size
is CX_STORE_POINTERS, the created map will be created as if cxMapStorePointers() was called immediately after creation.
index==size
.allocator | the allocator to use |
itemsize | the size of one element |
buckets | the initial number of buckets in this hash map |
int cxMapRehash | ( | CxMap * | map | ) |
Increases the number of buckets, if necessary.
The load threshold is 0.75*buckets
. If the element count exceeds the load threshold, the map will be rehashed. Otherwise, no action is performed and this function simply returns 0.
The rehashing process ensures, that the number of buckets is at least 2.5 times the element count. So there is enough room for additional elements without the need of another soon rehashing.
You can use this function after filling a map to increase access performance.
map | the map to rehash |