MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
linkhash.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <limits.h>
#include "random_seed.h"
#include "linkhash.h"

Go to the source code of this file.

Macros

#define HASH_LITTLE_ENDIAN   0
 
#define HASH_BIG_ENDIAN   0
 
#define hashsize(n)   ((uint32_t)1<<(n))
 
#define hashmask(n)   (hashsize(n)-1)
 
#define rot(x, k)   (((x)<<(k)) | ((x)>>(32-(k))))
 
#define mix(a, b, c)
 
#define final(a, b, c)
 

Functions

void lh_abort (const char *msg,...)
 
unsigned long lh_ptr_hash (const void *k)
 
int lh_ptr_equal (const void *k1, const void *k2)
 
static uint32_t hashlittle (const void *key, size_t length, uint32_t initval)
 
unsigned long lh_char_hash (const void *k)
 
int lh_char_equal (const void *k1, const void *k2)
 
struct lh_tablelh_table_new (int size, const char *name, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn, lh_equal_fn *equal_fn)
 
struct lh_tablelh_kchar_table_new (int size, const char *name, lh_entry_free_fn *free_fn)
 
struct lh_tablelh_kptr_table_new (int size, const char *name, lh_entry_free_fn *free_fn)
 
void lh_table_resize (struct lh_table *t, int new_size)
 
void lh_table_free (struct lh_table *t)
 
int lh_table_insert (struct lh_table *t, void *k, const void *v)
 
struct lh_entrylh_table_lookup_entry (struct lh_table *t, const void *k)
 
const void * lh_table_lookup (struct lh_table *t, const void *k)
 
json_bool lh_table_lookup_ex (struct lh_table *t, const void *k, void **v)
 
int lh_table_delete_entry (struct lh_table *t, struct lh_entry *e)
 
int lh_table_delete (struct lh_table *t, const void *k)
 
int lh_table_length (struct lh_table *t)
 

Macro Definition Documentation

#define HASH_LITTLE_ENDIAN   0

Definition at line 106 of file linkhash.c.

#define HASH_BIG_ENDIAN   0

Definition at line 107 of file linkhash.c.

#define hashsize (   n)    ((uint32_t)1<<(n))

Definition at line 110 of file linkhash.c.

#define hashmask (   n)    (hashsize(n)-1)

Definition at line 111 of file linkhash.c.

#define rot (   x,
 
)    (((x)<<(k)) | ((x)>>(32-(k))))

Definition at line 112 of file linkhash.c.

#define mix (   a,
  b,
 
)
Value:
{ \
a -= c; a ^= rot(c, 4); c += b; \
b -= a; b ^= rot(a, 6); a += c; \
c -= b; c ^= rot(b, 8); b += a; \
a -= c; a ^= rot(c,16); c += b; \
b -= a; b ^= rot(a,19); a += c; \
c -= b; c ^= rot(b, 4); b += a; \
}
#define rot(x, k)
Definition: linkhash.c:112

Definition at line 158 of file linkhash.c.

#define final (   a,
  b,
 
)
Value:
{ \
c ^= b; c -= rot(b,14); \
a ^= c; a -= rot(c,11); \
b ^= a; b -= rot(a,25); \
c ^= b; c -= rot(b,16); \
a ^= c; a -= rot(c,4); \
b ^= a; b -= rot(a,14); \
c ^= b; c -= rot(b,24); \
}
#define rot(x, k)
Definition: linkhash.c:112

Definition at line 193 of file linkhash.c.

Function Documentation

void lh_abort ( const char *  msg,
  ... 
)

Definition at line 27 of file linkhash.c.

unsigned long lh_ptr_hash ( const void *  k)

Pre-defined hash and equality functions

Definition at line 36 of file linkhash.c.

int lh_ptr_equal ( const void *  k1,
const void *  k2 
)

Definition at line 42 of file linkhash.c.

static uint32_t hashlittle ( const void *  key,
size_t  length,
uint32_t  initval 
)
static

Definition at line 232 of file linkhash.c.

unsigned long lh_char_hash ( const void *  k)

Definition at line 400 of file linkhash.c.

int lh_char_equal ( const void *  k1,
const void *  k2 
)

Definition at line 421 of file linkhash.c.

struct lh_table* lh_table_new ( int  size,
const char *  name,
lh_entry_free_fn free_fn,
lh_hash_fn hash_fn,
lh_equal_fn equal_fn 
)

Create a new linkhash table.

Parameters
sizeinitial table size. The table is automatically resized although this incurs a performance penalty.
namethe table name.
free_fncallback function used to free memory for entries when lh_table_free or lh_table_delete is called. If NULL is provided, then memory for keys and values must be freed by the caller.
hash_fnfunction used to hash keys. 2 standard ones are defined: lh_ptr_hash and lh_char_hash for hashing pointer values and C strings respectively.
equal_fncomparison function to compare keys. 2 standard ones defined: lh_ptr_hash and lh_char_hash for comparing pointer values and C strings respectively.
Returns
a pointer onto the linkhash table.

Definition at line 426 of file linkhash.c.

struct lh_table* lh_kchar_table_new ( int  size,
const char *  name,
lh_entry_free_fn free_fn 
)

Convenience function to create a new linkhash table with char keys.

Parameters
sizeinitial table size.
nametable name.
free_fncallback function used to free memory for entries.
Returns
a pointer onto the linkhash table.

Definition at line 448 of file linkhash.c.

struct lh_table* lh_kptr_table_new ( int  size,
const char *  name,
lh_entry_free_fn free_fn 
)

Convenience function to create a new linkhash table with ptr keys.

Parameters
sizeinitial table size.
nametable name.
free_fncallback function used to free memory for entries.
Returns
a pointer onto the linkhash table.

Definition at line 454 of file linkhash.c.

void lh_table_resize ( struct lh_table t,
int  new_size 
)

Definition at line 460 of file linkhash.c.

void lh_table_free ( struct lh_table t)

Free a linkhash table. If a callback free function is provided then it is called for all entries in the table.

Parameters
ttable to free.

Definition at line 480 of file linkhash.c.

int lh_table_insert ( struct lh_table t,
void *  k,
const void *  v 
)

Insert a record into the table.

Parameters
tthe table to insert into.
ka pointer to the key to insert.
va pointer to the value to insert.

Definition at line 493 of file linkhash.c.

struct lh_entry* lh_table_lookup_entry ( struct lh_table t,
const void *  k 
)

Lookup a record into the table.

Parameters
tthe table to lookup
ka pointer to the key to lookup
Returns
a pointer to the record structure of the value or NULL if it does not exist.

Definition at line 527 of file linkhash.c.

const void* lh_table_lookup ( struct lh_table t,
const void *  k 
)

Definition at line 545 of file linkhash.c.

json_bool lh_table_lookup_ex ( struct lh_table t,
const void *  k,
void **  v 
)

Lookup a record in the table

Parameters
tthe table to lookup
ka pointer to the key to lookup
va pointer to a where to store the found value (set to NULL if it doesn't exist).
Returns
whether or not the key was found

Definition at line 552 of file linkhash.c.

int lh_table_delete_entry ( struct lh_table t,
struct lh_entry e 
)

Delete a record from the table. If a callback free function is provided then it is called for the for the item being deleted.

Parameters
tthe table to delete from.
ea pointer to the entry to delete.
Returns
0 if the item was deleted.
-1 if it was not found.

Definition at line 563 of file linkhash.c.

int lh_table_delete ( struct lh_table t,
const void *  k 
)

Delete a record from the table. If a callback free function is provided then it is called for the for the item being deleted.

Parameters
tthe table to delete from.
ka pointer to the key to delete.
Returns
0 if the item was deleted.
-1 if it was not found.

Definition at line 592 of file linkhash.c.

int lh_table_length ( struct lh_table t)

Definition at line 599 of file linkhash.c.