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

strhmap.c File Reference

#include <cutk/strhmap.h>
#include <stdlib.h>

Defines

#define INLINE_X   static inline
#define INLINE   INLINE_X
#define SIZE_MAX   ((size_t)-1)

Functions

INLINE size_t NextPrime (size_t size)
INLINE size_t StrHash (const StrHmap *map, const char *s)
INLINE char StrEq (const char *s1, const char *s2)
INLINE int InsertNew (StrHmap *hashmap, const char *key, const void *item, size_t hash)
StrHmapStrHmapAlloc (size_t size)
void StrHmapFree (StrHmap *hashmap)
int StrHmapReserve (StrHmap *hashmap, size_t size)
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 StrHmapErase (StrHmap *hashmap, const char *key)
StrHmapStrHmapDup (const StrHmap *hashmap)
int StrHmapCompact (StrHmap *hashmap)
void StrHmapClear (StrHmap *hashmap)

Define Documentation

#define INLINE   INLINE_X
 

#define INLINE_X   static inline
 

#define SIZE_MAX   ((size_t)-1)
 


Function Documentation

INLINE int InsertNew StrHmap hashmap,
const char *  key,
const void *  item,
size_t  hash
 

INLINE size_t NextPrime size_t  size  ) 
 

INLINE char StrEq const char *  s1,
const char *  s2
 

INLINE size_t StrHash const StrHmap map,
const char *  s
 

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