The C Utility Toolkit
Main Page | Data Structures | File List | Data Fields | Globals

strhmap.h File Reference

#include <cutk/array.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  StrHmap_itemtype
struct  StrHmap

Defines

#define StrHmapSize(x)   (arysize(&(x)->items))

Typedefs

typedef StrHmap_itemtype StrHmap_itemtype
typedef StrHmap StrHmap

Functions

StrHmapStrHmapAlloc (size_t size)
void StrHmapClear (StrHmap *hashmap)
int StrHmapCompact (StrHmap *hashmap)
StrHmapStrHmapDup (const StrHmap *hashmap)
int StrHmapErase (StrHmap *hashmap, const char *key)
void StrHmapFree (StrHmap *hashmap)
void * StrHmapFind (StrHmap *hashmap, const char *key)
int StrHmapInsert (StrHmap *hashmap, const char *key, const void *item)
int StrHmapReplace (StrHmap *hashmap, const char *key, const void *item)
int StrHmapReserve (StrHmap *hashmap, size_t size)


Define Documentation

#define StrHmapSize  )     (arysize(&(x)->items))
 


Typedef Documentation

typedef struct StrHmap StrHmap
 

typedef struct StrHmap_itemtype StrHmap_itemtype
 


Function Documentation

StrHmap* StrHmapAlloc size_t  size  ) 
 

Allocate a new empty hash map.

Parameters:
size Specifies intial expected number of items in the hash map (can be 0).
Returns:
Returns a pointer to the new hash map or NULL on failure.

void StrHmapClear StrHmap hashmap  ) 
 

Erases all elements in a hash map.

Parameters:
hashmap Pointer to hash map

int StrHmapCompact StrHmap hashmap  ) 
 

Rebuilds a hash map. Erased items are removed from the hash map to free up memory.

Parameters:
hashmap Pointer to hash map
Returns:
0 on success; non-zero on failure

StrHmap* StrHmapDup const StrHmap hashmap  ) 
 

Duplicates a hash map.

Parameters:
hashmap Pointer to hash map
Returns:
Pointer to new hash map

int StrHmapErase StrHmap hashmap,
const char *  key
 

Erases an element from the hash map. Note that this will not free memory held by the hash map. Use StrHmaprehash to free up memory after items have been deleted.

Parameters:
hashmap Pointer to hash map
key Key to erase
Returns:
0 on success; non-zero on failure

void* StrHmapFind StrHmap hashmap,
const char *  key
 

Finds an element in the hash map.

Parameters:
hashmap Pointer to hash map
key Key to search for
Returns:
Pointer to element in hash map or NULL if key not found

void StrHmapFree StrHmap hashmap  ) 
 

Releases all memory held by a hash map.

Parameters:
hashmap Pointer to a hash map

int StrHmapInsert StrHmap hashmap,
const char *  key,
const void *  item
 

Inserts a new element into the hash map. This will return an error if the key already exists.

Parameters:
hashmap Pointer to hash map
key Key to insert element under
item Item pointer to insert into hash map
Returns:
0 on success; non-zero on failure

int StrHmapReplace StrHmap hashmap,
const char *  key,
const void *  item
 

Inserts or replaces an element in the hash map. This will overwrite existing items in the hash map.

Parameters:
hashmap Pointer to hash map
key Key to insert element under
item Item pointer to insert/replace in hash map
Returns:
0 on success; non-zero on failure

int StrHmapReserve StrHmap hashmap,
size_t  size
 

Reallocates a hash map. If the size is smaller than the actual number of elements in the hash map then the effect will be to reduce memory usage if possible. The size can be larger than the actual number of elements in the hash map which will allow lots of insertions to go faster since the table won't need to be resized as often.

Parameters:
hashmap Pointer to hash map
size Number of elements to preallocate
Returns:
0 on success; non-zero on failure


Generated on Wed Jan 12 13:13:42 2005 for CUTK by doxygen 1.3.7