![]() |
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(NULL, itemsize, 0) |
Creates a new hash map with a default number of buckets. | |
Functions | |
CxMap * | cxHashMapCreate (const CxAllocator *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(NULL, itemsize, 0) |
Creates a new hash map with a default number of buckets.
If elem_size
is CX_STORE_POINTERS, the created map stores pointers instead of copies of the added elements.
index==size
.itemsize | (size_t ) the size of one element |
CxMap*
) a pointer to the new hash map CxMap * cxHashMapCreate | ( | const CxAllocator * | 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 elem_size
is CX_STORE_POINTERS, the created map stores pointers instead of copies of the added elements.
index==size
.allocator | the allocator to use (if NULL , a default stdlib allocator will be used) |
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 |
zero | success |
non-zero | if a memory allocation error occurred |