ucx
UAP Common Extensions
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
hash_map.h File Reference

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

CxMapcxHashMapCreate (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.
 

Detailed Description

Hash map implementation.

Author
Mike Becker
Olaf Wintermann
Version
3.0

Macro Definition Documentation

◆ cxHashMapCreateSimple

#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.

Note
Iterators provided by this hash map implementation provide the remove operation. The index value of an iterator is incremented when the iterator advanced without removal. In other words, when the iterator is finished, index==size .
Parameters
itemsizethe size of one element
Returns
a pointer to the new hash map

Function Documentation

◆ cxHashMapCreate()

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.

Note
Iterators provided by this hash map implementation provide the remove operation. The index value of an iterator is incremented when the iterator advanced without removal. In other words, when the iterator is finished, index==size .
Parameters
allocatorthe allocator to use
itemsizethe size of one element
bucketsthe initial number of buckets in this hash map
Returns
a pointer to the new hash map

◆ cxMapRehash()

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.

Note
If the specified map is not a hash map, the behavior is undefined.
Parameters
mapthe map to rehash
Returns
zero on success, non-zero if a memory allocation error occurred