XBinder  Version 2.6.x
Functions
rtxHashMap.h File Reference

Generic hash map interface. More...

#include "rtxsrc/rtxContext.h"

Go to the source code of this file.

Functions

EXTERNRT void HASHMAPINITFUNC (OSCTXT *pctxt, HASHMAPTYPENAME *pHashMap, size_t capacity, OSUINT32(*hashFunc)(HASHMAPKEYTYPE), OSBOOL(*keyEqualsFunc)(HASHMAPKEYTYPE, HASHMAPKEYTYPE))
 This function initializes the hash map. More...
 
EXTERNRT HASHMAPTYPENAME * HASHMAPNEWFUNC (OSCTXT *pctxt, size_t capacity, OSUINT32(*hashFunc)(HASHMAPKEYTYPE), OSBOOL(*keyEqualsFunc)(HASHMAPKEYTYPE, HASHMAPKEYTYPE))
 This function creates a new hash map. More...
 
EXTERNRT HASHMAPTYPENAME * HASHMAPCOPYFUNC (OSCTXT *pctxt, HASHMAPTYPENAME *pHashMap)
 This function creates a copy of an existing hash map. More...
 
EXTERNRT void HASHMAPFREEFUNC (OSCTXT *pctxt, HASHMAPTYPENAME *pHashMap)
 This function frees all entries within an existing hash map. More...
 
EXTERNRT int HASHMAPINSERTFUNC (OSCTXT *pctxt, HASHMAPTYPENAME *pHashMap, HASHMAPKEYTYPE key, HASHMAPVALUETYPE value)
 This function inserts an entry into the hash map. More...
 
EXTERNRT OSBOOL HASHMAPSEARCHFUNC (HASHMAPTYPENAME *pHashMap, HASHMAPKEYTYPE key, HASHMAPVALUETYPE *pvalue)
 This function searches for an entry in the hash map. More...
 
EXTERNRT OSBOOL HASHMAPREMOVEFUNC (OSCTXT *pctxt, HASHMAPTYPENAME *pHashMap, HASHMAPKEYTYPE key, HASHMAPVALUETYPE *pvalue)
 This function removes an entry from the hash map. More...
 
EXTERNRT int HASHMAPPUTFUNC (OSCTXT *pctxt, HASHMAPTYPENAME *pHashMap, HASHMAPKEYTYPE key, HASHMAPVALUETYPE value)
 This function inserts/replaces an entry into the hash map. More...
 
EXTERNRT int HASHMAPSORTFUNC (OSCTXT *pctxt, HASHMAPTYPENAME *pHashMap, OSRTDList *pSortedList, int(*compareFunc)(HASHMAPKEYTYPE key1, HASHMAPKEYTYPE key2))
 This function sorts the hash map in ascending order using the given key compare function. More...
 

Detailed Description

Generic hash map interface.

This relates a generic key structure (void*) to a generic value (void*). Based on "C Hash Table" public domain code (http://www.cl.cam.ac.uk/~cwc22/hashtable/).

Definition in file rtxHashMap.h.

Function Documentation

◆ HASHMAPCOPYFUNC()

EXTERNRT HASHMAPTYPENAME* HASHMAPCOPYFUNC ( OSCTXT pctxt,
HASHMAPTYPENAME *  pHashMap 
)

This function creates a copy of an existing hash map.

Parameters
pctxtPointer to a context structure.
pHashMapPointer to hash map structure to copy.
Returns
Allocated and copied hash map structure or NULL if insufficient dynamic memory is available to hold the structure.

◆ HASHMAPFREEFUNC()

EXTERNRT void HASHMAPFREEFUNC ( OSCTXT pctxt,
HASHMAPTYPENAME *  pHashMap 
)

This function frees all entries within an existing hash map.

It does not free the structure itself.

Parameters
pctxtPointer to a context structure.
pHashMapPointer to hash map structure to free.

◆ HASHMAPINITFUNC()

EXTERNRT void HASHMAPINITFUNC ( OSCTXT pctxt,
HASHMAPTYPENAME *  pHashMap,
size_t  capacity,
OSUINT32(*)(HASHMAPKEYTYPE)  hashFunc,
OSBOOL(*)(HASHMAPKEYTYPE, HASHMAPKEYTYPE)  keyEqualsFunc 
)

This function initializes the hash map.

Parameters
pctxtPointer to a context structure.
pHashMapPointer to hash map structure.
capacityCapacity of the hash map or zero to use default.
hashFuncHash callback function.
keyEqualsFuncKey equals callback function.

◆ HASHMAPINSERTFUNC()

EXTERNRT int HASHMAPINSERTFUNC ( OSCTXT pctxt,
HASHMAPTYPENAME *  pHashMap,
HASHMAPKEYTYPE  key,
HASHMAPVALUETYPE  value 
)

This function inserts an entry into the hash map.

The table will be expanded if the insertion would take the ratio of entries to table size over the maximum load factor.

This function does not check for repeated insertions with a duplicate key. The value returned when using a duplicate key is undefined – when the hashtable changes size, the order of retrieval of duplicate key entries is reversed. If in doubt, remove before insert.

Parameters
pctxtPointer to a context structure.
pHashMapPointer to hash map structure.
keyKey value. Memory is owned by caller.
valueValue to insert. Memory is owned by caller.
Returns
Zero if insertion was successful, a negative status code otherwise.

◆ HASHMAPNEWFUNC()

EXTERNRT HASHMAPTYPENAME* HASHMAPNEWFUNC ( OSCTXT pctxt,
size_t  capacity,
OSUINT32(*)(HASHMAPKEYTYPE)  hashFunc,
OSBOOL(*)(HASHMAPKEYTYPE, HASHMAPKEYTYPE)  keyEqualsFunc 
)

This function creates a new hash map.

Parameters
pctxtPointer to a context structure.
capacityCapacity of the map or zero to use default.
hashFuncHash callback function.
keyEqualsFuncKey equals callback function.
Returns
Allocated hash map structure or NULL if insufficient dynamic memory is available to hold the structure.

◆ HASHMAPPUTFUNC()

EXTERNRT int HASHMAPPUTFUNC ( OSCTXT pctxt,
HASHMAPTYPENAME *  pHashMap,
HASHMAPKEYTYPE  key,
HASHMAPVALUETYPE  value 
)

This function inserts/replaces an entry into the hash map.

If the key already exists in the map, its value is updated. Otherwise, the key/value pair is inserted.

Parameters
pctxtPointer to a context structure.
pHashMapPointer to hash map structure.
keyKey value. Memory is owned by caller.
valueValue to insert/replace. Memory is owned by caller.
Returns
Zero if operation was successful, a negative status code otherwise.

◆ HASHMAPREMOVEFUNC()

EXTERNRT OSBOOL HASHMAPREMOVEFUNC ( OSCTXT pctxt,
HASHMAPTYPENAME *  pHashMap,
HASHMAPKEYTYPE  key,
HASHMAPVALUETYPE *  pvalue 
)

This function removes an entry from the hash map.

Parameters
pctxtPointer to a context structure.
pHashMapPointer to hash map structure.
keyKey value. Memory is owned by caller.
pvaluePointer to value to receive search result value.
Returns
Boolean result: true if found and removed.

◆ HASHMAPSEARCHFUNC()

EXTERNRT OSBOOL HASHMAPSEARCHFUNC ( HASHMAPTYPENAME *  pHashMap,
HASHMAPKEYTYPE  key,
HASHMAPVALUETYPE *  pvalue 
)

This function searches for an entry in the hash map.

Parameters
pHashMapPointer to hash map structure.
keyKey value. Memory is owned by caller.
pvaluePointer to value to receive search result value.
Returns
Boolean search result: true if found; false if not.

◆ HASHMAPSORTFUNC()

EXTERNRT int HASHMAPSORTFUNC ( OSCTXT pctxt,
HASHMAPTYPENAME *  pHashMap,
OSRTDList pSortedList,
int(*)(HASHMAPKEYTYPE key1, HASHMAPKEYTYPE key2)  compareFunc 
)

This function sorts the hash map in ascending order using the given key compare function.

Parameters
pctxtPointer to a context structure.
pHashMapPointer to hash map structure.
compareFuncComparison function for key values.
pSortedListPointer to linked list structure to receive sorted values. Entries within the list are items from the hash map themselves, not copies. List memory may be freed by calling rtxDListFreeNodes.
Returns
Status of operation: 0 = success or negative status code.