regify utility  2.0.0-0
Hash Map

This section contains a hash map implementation. More...

Macros

#define ruMapPut(map, key, val)   ruMapPutData(map, (ptr)(key), (ptr)(val), NULL)
 Runs ruMapPutData with ptr casts. More...
 
#define ruMapTryPut(map, key, val, existing)   ruMapPutData(map, (ptr)(key), (ptr)(val), (ptr*)(existing))
 Runs ruMapPutData with ptr casts. More...
 
#define ruMapRemove(rm, key, val)   ruMapRemoveData(rm, (trans_ptr)(key), (ptr*)(val))
 Runs ruMapRemoveData with ptr casts. More...
 
#define ruMapGet(rm, key, val)   ruMapGetValue(rm, (trans_ptr)(key), (ptr*)(val))
 Runs ruMapGetValue with a ptr cast. More...
 
#define ruMapHas(rm, key, code)   ruMapHasKey(rm, (trans_ptr)(key), code)
 Runs ruMapHasKey with a ptr casted key. More...
 
#define ruMapFirst(rm, key, value)   ruMapFirstSet(rm, (ptr*)(key), (ptr*)(value))
 Runs ruMapFirstSet with ptr casts. More...
 
#define ruMapNext(rm, key, value)   ruMapNextSet(rm, (ptr*)(key), (ptr*)(value))
 Runs ruMapNextSet with ptr casts. More...
 

Typedefs

typedef void * ruMap
 An opaque type representing a map object. More...
 

Functions

RUAPI ruMap ruMapNew (ruType keyType, ruType valueType)
 Creates a new ruMap based on the given specifications. More...
 
RUAPI ruMap ruMapFree (ruMap rm)
 Frees the given map and its members. More...
 
RUAPI int32_t ruMapPutData (ruMap rm, ptr key, ptr val, ptr *exisitingVal)
 Insert a key/val pair into the map. More...
 
RUAPI int32_t ruMapRemoveData (ruMap rm, trans_ptr key, ptr *val)
 Removes an entry from the map. More...
 
RUAPI int32_t ruMapRemoveAll (ruMap rm)
 Removes all entries from the map. More...
 
RUAPI int32_t ruMapGetValue (ruMap rm, trans_ptr key, ptr *val)
 Retrieves an pointer entry from the map. More...
 
RUAPI bool ruMapHasKey (ruMap rm, trans_ptr key, int32_t *code)
 Tests whether map has an entry for given key. More...
 
RUAPI int32_t ruMapFirstSet (ruMap rm, ptr *key, ptr *value)
 Initializes a map iterator and populates given parameters with the first key pair to serve as a for loop initializer. More...
 
RUAPI int32_t ruMapNextSet (ruMap rm, ptr *key, ptr *value)
 Retrieves the next key/value pair from the map. More...
 
RUAPI int32_t ruMapKeyList (ruMap rm, ruList *keys)
 Return a key list of the given map. More...
 
RUAPI uint32_t ruMapSize (ruMap rm, int32_t *code)
 Returns the size of the map. More...
 

Detailed Description

This section contains a hash map implementation.

Macro Definition Documentation

◆ ruMapFirst

#define ruMapFirst (   rm,
  key,
  value 
)    ruMapFirstSet(rm, (ptr*)(key), (ptr*)(value))

Runs ruMapFirstSet with ptr casts.

Example:

int ret;
void *key = NULL, *val = NULL; // map values must be pointer sized
for (ret = ruMapFirst(map, &key, &val); ret == RUE_OK;
ret = ruMapNext(map, &key, &val)) {
// work with key and/or val
}
#define ruMapFirst(rm, key, value)
Runs ruMapFirstSet with ptr casts.
Definition: map.h:194
#define ruMapNext(rm, key, value)
Runs ruMapNextSet with ptr casts.
Definition: map.h:215
#define RUE_OK
Definition: errors.h:66

NOTE: Either key or value must be set.

Parameters
rmThe map to iterate over.
keyWhere to store the current key. (optional)
valueWhere to store the current value. (optional)
Returns
RUE_OK on success RUE_FILE_NOT_FOUND at the end of the set RUE_USER_ABORT when a threaded map has quit else a regify error code.

◆ ruMapGet

#define ruMapGet (   rm,
  key,
  val 
)    ruMapGetValue(rm, (trans_ptr)(key), (ptr*)(val))

Runs ruMapGetValue with a ptr cast.

◆ ruMapHas

#define ruMapHas (   rm,
  key,
  code 
)    ruMapHasKey(rm, (trans_ptr)(key), code)

Runs ruMapHasKey with a ptr casted key.

Parameters
rmThe map to check.
keyThe key to be searched.
code(Optional) Stores RUE_OK on success RUE_USER_ABORT when a threaded map has quit else a regify error code.
Returns
true if key exists or false on error or if not.

◆ ruMapNext

#define ruMapNext (   rm,
  key,
  value 
)    ruMapNextSet(rm, (ptr*)(key), (ptr*)(value))

Runs ruMapNextSet with ptr casts.

◆ ruMapPut

#define ruMapPut (   map,
  key,
  val 
)    ruMapPutData(map, (ptr)(key), (ptr)(val), NULL)

Runs ruMapPutData with ptr casts.

Parameters
mapMap to insert key / value pair into.
keyThe key to insert. For numeric specs this must be an address to the underlying variable.
valThe associated value to go with the key. For numeric specs this must be an address to the underlying variable.
Returns
RUE_OK on success RUE_USER_ABORT when a threaded map has quit else a regify error code.

◆ ruMapRemove

#define ruMapRemove (   rm,
  key,
  val 
)    ruMapRemoveData(rm, (trans_ptr)(key), (ptr*)(val))

Runs ruMapRemoveData with ptr casts.

Parameters
rmThe map to remove the entry from.
keyThe key to be removed.
val(Optional) Where to store the retrieved value associated with the key.
Returns
RUE_OK on success RUE_USER_ABORT when a threaded map has quit else a regify error code.

◆ ruMapTryPut

#define ruMapTryPut (   map,
  key,
  val,
  existing 
)    ruMapPutData(map, (ptr)(key), (ptr)(val), (ptr*)(existing))

Runs ruMapPutData with ptr casts.

Parameters
mapMap to insert key / value pair into.
keyThe key to insert.
valThe associated value to go with the key.
existingOptional. If set the pointer to the associated existing value will be stored here, and key/value will not be updated.
Returns
RUE_OK on success, RUE_FILE_EXISTS if exisitingVal was set and there was one, RUE_USER_ABORT when a threaded map has quit else a regify error code.

Typedef Documentation

◆ ruMap

typedef void* ruMap

An opaque type representing a map object.

Function Documentation

◆ ruMapFirstSet()

RUAPI int32_t ruMapFirstSet ( ruMap  rm,
ptr key,
ptr value 
)

Initializes a map iterator and populates given parameters with the first key pair to serve as a for loop initializer.

NOTE: Either key or value must be set.

Parameters
rmThe map to iterate over.
keyWhere to store the current key. (optional)
valueWhere to store the current value. (optional)
Returns
RUE_OK on success RUE_FILE_NOT_FOUND at the end of the set RUE_USER_ABORT when a threaded map has quit else a regify error code.

◆ ruMapFree()

RUAPI ruMap ruMapFree ( ruMap  rm)

Frees the given map and its members.

Parameters
rmMap to free
Returns
NULL

◆ ruMapGetValue()

RUAPI int32_t ruMapGetValue ( ruMap  rm,
trans_ptr  key,
ptr val 
)

Retrieves an pointer entry from the map.

Parameters
rmThe map to retrieve the entry from.
keyThe key to be retrieved.
valWhere to store the retrieved value associated with the key.
Returns
RUE_OK on success RUE_GENERAL if key was not found RUE_USER_ABORT when a threaded map has quit else a regify error code.

◆ ruMapHasKey()

RUAPI bool ruMapHasKey ( ruMap  rm,
trans_ptr  key,
int32_t *  code 
)

Tests whether map has an entry for given key.

Parameters
rmThe map to check.
keyThe key to be searched.
code(Optional) Stores RUE_OK on success RUE_USER_ABORT when a threaded map has quit else a regify error code.
Returns
true if key exists or false on error or if not.

◆ ruMapKeyList()

RUAPI int32_t ruMapKeyList ( ruMap  rm,
ruList keys 
)

Return a key list of the given map.

Parameters
rmThe map to get the key list from.
keysWhere to store the resulting list.
Returns
RUE_OK on success, RUE_USER_ABORT when a threaded map has quit else a regify error code.

◆ ruMapNew()

RUAPI ruMap ruMapNew ( ruType  keyType,
ruType  valueType 
)

Creates a new ruMap based on the given specifications.

Parameters
keyTypeA key specification. Will be freed by this call.
valueTypeA value specification. Will be freed by this call.
Returns
Newly create map. Caller m ust free with ruMapFree.

◆ ruMapNextSet()

RUAPI int32_t ruMapNextSet ( ruMap  rm,
ptr key,
ptr value 
)

Retrieves the next key/value pair from the map.

NOTE: Either key or value must be set.

Parameters
rmThe map to retrieve the entry from.
keyWhere to store the current key. (optional)
valueWhere to store the current value. (optional)
Returns
RUE_OK on success, RUE_FILE_NOT_FOUND at the end of the set RUE_INVALID_STATE if ruMapFirstSet hasn't been called or been invalidated. RUE_USER_ABORT when a threaded map has quit else a regify error code.

◆ ruMapPutData()

RUAPI int32_t ruMapPutData ( ruMap  rm,
ptr  key,
ptr  val,
ptr exisitingVal 
)

Insert a key/val pair into the map.

Parameters
rmMap to insert key / value pair into.
keyThe key to insert. For numeric specs this must be an address to the underlying variable.
valThe associated value to go with the key. For numeric specs this must be an address to the underlying variable.
exisitingValOptional. If set the pointer to the associated existing value will be stored here, and key/value will not be updated.
Returns
RUE_OK on success, RUE_FILE_EXISTS if exisitingVal was set and there was one, RUE_USER_ABORT when a threaded map has quit else a regify error code.

◆ ruMapRemoveAll()

RUAPI int32_t ruMapRemoveAll ( ruMap  rm)

Removes all entries from the map.

Parameters
rmThe map to remove the entry from.
Returns
RUE_OK on success RUE_USER_ABORT when a threaded map has quit else a regify error code.

◆ ruMapRemoveData()

RUAPI int32_t ruMapRemoveData ( ruMap  rm,
trans_ptr  key,
ptr val 
)

Removes an entry from the map.

Parameters
rmThe map to remove the entry from.
keyThe key to be removed.
val(Optional) Where to store the retrieved value associated with the key.
Returns
RUE_OK on success RUE_USER_ABORT when a threaded map has quit else a regify error code.

◆ ruMapSize()

RUAPI uint32_t ruMapSize ( ruMap  rm,
int32_t *  code 
)

Returns the size of the map.

Parameters
rmMap to return the size of.
code(Optional) Stores RUE_OK on success or regify error code.
Returns
Size of the map or 0 on error.