CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions
clixon_hash.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <inttypes.h>
#include "clixon_queue.h"
#include "clixon_err.h"
#include "clixon_hash.h"

Macros

#define HASH_SIZE   1031 /* Number of hash buckets. Should be a prime */
 

Functions

static uint32_t hash_bucket (const char *str)
 
clicon_hash_t * hash_init (void)
 
void hash_free (clicon_hash_t *hash)
 
clicon_hash_t hash_lookup (clicon_hash_t *hash, const char *key)
 
void * hash_value (clicon_hash_t *hash, const char *key, size_t *vlen)
 
clicon_hash_t hash_add (clicon_hash_t *hash, const char *key, void *val, size_t vlen)
 
int hash_del (clicon_hash_t *hash, const char *key)
 
char ** hash_keys (clicon_hash_t *hash, size_t *nkeys)
 
void hash_dump (clicon_hash_t *hash, FILE *f)
 

Macro Definition Documentation

#define HASH_SIZE   1031 /* Number of hash buckets. Should be a prime */

Function Documentation

clicon_hash_t hash_add ( clicon_hash_t *  hash,
const char *  key,
void *  val,
size_t  vlen 
)

Copy value and add hash entry.

Parameters
[in]hashHash table
[in]keyNew variable name
[in]valNew variable value
[in]vlenLength of variable value
Return values
variableNew hash structure on success
NULLFailure
static uint32_t hash_bucket ( const char *  str)
static

A very simplistic algorithm to calculate a hash bucket index

int hash_del ( clicon_hash_t *  hash,
const char *  key 
)

Delete hash entry.

Parameters
[in]hashHash table
[in]keyVariable name
Return values
0success
-1failure
void hash_dump ( clicon_hash_t *  hash,
FILE *  f 
)

Dump contents of hash to FILE pointer.

Parameters
[in]hashHash structure
[in]fFILE pointer for print output
Return values
void
void hash_free ( clicon_hash_t *  hash)

Free hash table.

Parameters
[in]hashHash table
Return values
void
clicon_hash_t* hash_init ( void  )

Initialize hash table.

Return values
Pointerto new hash table.
char** hash_keys ( clicon_hash_t *  hash,
size_t *  nkeys 
)

Return vector of keys in has table

Parameters
[in]hashHash table
[out]nkeysSize of key vector
Return values
vectorVector of keys
NULLError
clicon_hash_t hash_lookup ( clicon_hash_t *  hash,
const char *  key 
)

Find hash key.

Parameters
[in]hashHash table
[in]keyVariable name
Return values
variableHash variable structure on success
NULLError
void* hash_value ( clicon_hash_t *  hash,
const char *  key,
size_t *  vlen 
)

Get value of hash

Parameters
[in]hashHash table
[in]keyVariable name
[out]vlenLength of value (as returned by function)
Return values
valueHash value, length given in vlen
NULLError