Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

sfxhash.h File Reference

#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "sfmemcap.h"
#include "sfhashfcn.h"

Go to the source code of this file.

Defines

#define SFXHASH_NOMEM   -2
#define SFXHASH_ERR   -1
#define SFXHASH_OK   0
#define SFXHASH_INTABLE   1

Typedefs

typedef _sfxhash_node SFXHASH_NODE
typedef _sfxhash SFXHASH

Functions

SFXHASHsfxhash_new (int nrows, int keysize, int datasize, int memcap, int anr_flag, int(*anrfunc)(void *key, void *data), int(*usrfunc)(void *key, void *data), int recycle_flag)
void sfxhash_delete (SFXHASH *h)
int sfxhash_add (SFXHASH *h, void *key, void *data)
SFXHASH_NODEsfxhash_get_node (SFXHASH *t, void *key)
int sfxhash_remove (SFXHASH *h, void *key)
unsigned sfxhash_count (SFXHASH *h)
unsigned sfxhash_anr_count (SFXHASH *h)
void * sfxhash_mru (SFXHASH *t)
void * sfxhash_lru (SFXHASH *t)
SFXHASH_NODEsfxhash_mru_node (SFXHASH *t)
SFXHASH_NODEsfxhash_lru_node (SFXHASH *t)
void * sfxhash_find (SFXHASH *h, void *key)
SFXHASH_NODEsfxhash_find_node (SFXHASH *t, void *key)
SFXHASH_NODEsfxhash_findfirst (SFXHASH *h)
SFXHASH_NODEsfxhash_findnext (SFXHASH *h)
SFXHASH_NODEsfxhash_ghead (SFXHASH *h)
SFXHASH_NODEsfxhash_gnext (SFXHASH_NODE *n)
void sfxhash_gmovetofront (SFXHASH *t, SFXHASH_NODE *hnode)
void sfxhash_splaymode (SFXHASH *h, int mode)
void * sfxhash_alloc (SFXHASH *t, unsigned nbytes)
void sfxhash_free (SFXHASH *t, void *p)
int sfxhash_free_node (SFXHASH *t, SFXHASH_NODE *node)
unsigned sfxhash_maxdepth (SFXHASH *t)
unsigned sfxhash_overhead_bytes (SFXHASH *t)
unsigned sfxhash_overhead_blocks (SFXHASH *t)
unsigned sfxhash_find_success (SFXHASH *h)
unsigned sfxhash_find_fail (SFXHASH *h)
unsigned sfxhash_find_total (SFXHASH *h)
int sfxhash_set_keyops (SFXHASH *h, unsigned(*hash_fcn)(SFHASHFCN *p, unsigned char *d, int n), int(*keycmp_fcn)(const void *s1, const void *s2, size_t n))


Define Documentation

#define SFXHASH_ERR   -1
 

Definition at line 26 of file sfxhash.h.

Referenced by sfxhash_remove().

#define SFXHASH_INTABLE   1
 

Definition at line 28 of file sfxhash.h.

Referenced by flowcache_newflow(), Frag3NewTracker(), scoreboard_add(), server_stats_add_ipv4(), sfthd_test_gobject(), sfthd_test_object(), sfxhash_add(), and ut_check().

#define SFXHASH_NOMEM   -2
 

Definition at line 25 of file sfxhash.h.

Referenced by flowcache_newflow(), scoreboard_add(), server_stats_add_ipv4(), sfxhash_add(), and ut_check().

#define SFXHASH_OK   0
 

Definition at line 27 of file sfxhash.h.

Referenced by flowcache_newflow(), Frag3NewTracker(), Frag3RemoveTracker(), ps_tracker_get(), scoreboard_add(), server_stats_add_ipv4(), sfxhash_add(), sfxhash_free_node(), and ut_check().


Typedef Documentation

typedef struct _sfxhash SFXHASH
 

typedef struct _sfxhash_node SFXHASH_NODE
 


Function Documentation

int sfxhash_add SFXHASH t,
void *  key,
void *  data
 

Add a key + data pair to the hash table

2003-06-06:

  • unique_tracker.c assumes that this splays nodes to the top when they are added.

This is done because of the successful find.

Parameters:
t SFXHASH table pointer
key users key pointer
data users data pointer
Returns:
integer
Return values:
SFXHASH_OK success
SFXHASH_INTABLE already in the table, t->cnode points to the node
SFXHASH_NOMEM not enough memory

Definition at line 654 of file sfxhash.c.

References _sfxhash::cnode, _sfxhash::count, _sfxhash_node::data, _sfxhash::datasize, index, _sfxhash_node::key, _sfxhash::keysize, memcpy, _sfxhash_node::rindex, sfxhash_find_node_row(), sfxhash_glink_node(), SFXHASH_INTABLE, sfxhash_link_node(), sfxhash_newnode(), SFXHASH_NOMEM, and SFXHASH_OK.

Referenced by flowcache_newflow(), Frag3NewTracker(), ps_tracker_get(), scoreboard_add(), server_stats_add_ipv4(), server_stats_load(), sfthd_test_gobject(), sfthd_test_object(), and ut_check().

void* sfxhash_alloc SFXHASH t,
unsigned  nbytes
 

Definition at line 95 of file sfxhash.c.

References s_malloc().

unsigned sfxhash_anr_count SFXHASH t  ) 
 

Get the # auto recovery

Parameters:
t SFXHASH table pointer

Definition at line 318 of file sfxhash.c.

References _sfxhash::anr_count.

Referenced by flowcache_stats(), scoreboard_stats(), server_stats(), and ut_stats().

unsigned sfxhash_count SFXHASH t  ) 
 

Get the # of Nodes in HASH the table

Parameters:
t SFXHASH table pointer

Definition at line 307 of file sfxhash.c.

References _sfxhash::count.

Referenced by CleanHashTable(), flowcache_stats(), Frag3Defrag(), Frag3GetTracker(), PrintSessionCache(), scoreboard_stats(), server_stats(), and ut_stats().

void sfxhash_delete SFXHASH h  ) 
 

Delete the hash Table

free key's, free node's, and free the users data.

Parameters:
h SFXHASH table pointer

Definition at line 269 of file sfxhash.c.

References _sfxhash_node::data, _sfxhash_node::key, _sfxhash_node::next, _sfxhash::nrows, s_free(), _sfxhash::sfhashfcn, sfhashfcn_free(), _sfxhash::table, and _sfxhash::usrfree.

Referenced by flowcache_destroy(), flowcache_init(), scoreboard_destroy(), server_stats_destroy(), server_stats_init(), and ut_destroy().

void* sfxhash_find SFXHASH t,
void *  key
 

Find the users data based associated with the key

Parameters:
t SFXHASH table pointer
key users key pointer
Returns:
void* valid pointer to the users data
Return values:
0 node not found

Definition at line 817 of file sfxhash.c.

References _sfxhash_node::data, NULL, and sfxhash_find_node_row().

Referenced by flowcache_find(), Frag3GetTracker(), ps_tracker_get(), scoreboard_find(), and server_stats_hitcount_ipv4().

unsigned sfxhash_find_fail SFXHASH t  ) 
 

Get the # unsucessful finds

Parameters:
t SFXHASH table pointer

Definition at line 340 of file sfxhash.c.

References _sfxhash::find_fail.

Referenced by scoreboard_stats(), server_stats(), and ut_stats().

SFXHASH_NODE* sfxhash_find_node SFXHASH t,
void *  key
 

Find a Node based on the key

Parameters:
t SFXHASH table pointer
key users key pointer
Returns:
SFXHASH_NODE* valid pointer to the hash node
Return values:
0 node not found

Definition at line 800 of file sfxhash.c.

References sfxhash_find_node_row().

Referenced by GetSessionFromHashTable().

unsigned sfxhash_find_success SFXHASH t  ) 
 

Get the # sucessful finds

Parameters:
t SFXHASH table pointer

Definition at line 351 of file sfxhash.c.

References _sfxhash::find_success.

Referenced by scoreboard_stats(), server_stats(), and ut_stats().

unsigned sfxhash_find_total SFXHASH t  ) 
 

Get the # finds

Parameters:
t SFXHASH table pointer

Definition at line 329 of file sfxhash.c.

References _sfxhash::find_fail, and _sfxhash::find_success.

Referenced by scoreboard_stats(), server_stats(), and ut_stats().

SFXHASH_NODE* sfxhash_findfirst SFXHASH t  ) 
 

Find and return the first hash table node

Parameters:
t SFXHASH table pointer
Returns:
0 failed
Return values:
!0 valid SFXHASH_NODE *

Definition at line 1079 of file sfxhash.c.

References _sfxhash::cnode, _sfxhash::crow, _sfxhash::nrows, NULL, sfxhash_next(), and _sfxhash::table.

SFXHASH_NODE* sfxhash_findnext SFXHASH t  ) 
 

Find and return the next hash table node

Parameters:
t SFXHASH table pointer
Returns:
0 failed
Return values:
!0 valid SFXHASH_NODE *

Definition at line 1108 of file sfxhash.c.

References _sfxhash::cnode, NULL, and sfxhash_next().

void sfxhash_free SFXHASH t,
void *  p
 

Definition at line 99 of file sfxhash.c.

References s_free().

int sfxhash_free_node SFXHASH t,
SFXHASH_NODE node
 

Definition at line 984 of file sfxhash.c.

References _sfxhash::count, _sfxhash_node::data, _sfxhash_node::key, _sfxhash::recycle_nodes, s_free(), sfxhash_gunlink_node(), SFXHASH_OK, sfxhash_save_free_node(), sfxhash_unlink_node(), and _sfxhash::usrfree.

Referenced by Frag3Expire(), and sfxhash_remove().

SFXHASH_NODE* sfxhash_get_node SFXHASH t,
void *  key
 

Add a key to the hash table, return the hash node

2003-06-06:

  • unique_tracker.c assumes that this splays nodes to the top when they are added.

This is done because of the successful find.

Parameters:
t SFXHASH table pointer
key users key pointer
Returns:
integer
Return values:
SFXHASH_OK success
SFXHASH_INTABLE already in the table, t->cnode points to the node
SFXHASH_NOMEM not enough memory

Definition at line 733 of file sfxhash.c.

References _sfxhash::cnode, _sfxhash::count, _sfxhash_node::data, _sfxhash::datasize, index, _sfxhash_node::key, _sfxhash::keysize, memcpy, NULL, _sfxhash_node::rindex, sfxhash_find_node_row(), sfxhash_glink_node(), sfxhash_link_node(), and sfxhash_newnode().

Referenced by flowcache_newflow(), Frag3NewTracker(), and GetNewSession().

SFXHASH_NODE* sfxhash_ghead SFXHASH t  ) 
 

Get the HEAD of the in use list

Parameters:
t table pointer
Returns:
the head of the list or NULL

Definition at line 837 of file sfxhash.c.

References _sfxhash::ghead, and NULL.

Referenced by scoreboard_dump(), server_stats_dump(), server_stats_save(), sfxhash_mru(), sfxhash_mru_node(), and unique_tracker_dump().

void sfxhash_gmovetofront SFXHASH t,
SFXHASH_NODE hnode
 

Definition at line 462 of file sfxhash.c.

References _sfxhash::ghead, sfxhash_glink_node(), and sfxhash_gunlink_node().

Referenced by CleanHashTable(), Frag3Prune(), and movetofront().

SFXHASH_NODE* sfxhash_gnext SFXHASH_NODE n  ) 
 

Walk the global list

Parameters:
n current node
Returns:
the next node in the list or NULL when at the end

Definition at line 855 of file sfxhash.c.

References _sfxhash_node::gnext, and NULL.

Referenced by scoreboard_dump(), server_stats_dump(), server_stats_save(), and unique_tracker_dump().

void* sfxhash_lru SFXHASH t  ) 
 

Return the least recently used data from the global list

Parameters:
t SFXHASH table pointer
Returns:
void* valid pointer to the users data
Return values:
0 node not found

Definition at line 896 of file sfxhash.c.

References _sfxhash_node::data, _sfxhash::gtail, and NULL.

Referenced by CleanHashTable(), flowcache_lru(), Frag3Expire(), and scoreboard_lru().

SFXHASH_NODE* sfxhash_lru_node SFXHASH t  ) 
 

Return the least recently used node from the global list

Parameters:
t SFXHASH table pointer
Returns:
SFXHASH_NODE* valid pointer to a node
Return values:
0 node not found

Definition at line 937 of file sfxhash.c.

References _sfxhash::gtail, and NULL.

Referenced by CleanHashTable(), Frag3Expire(), and Frag3Prune().

unsigned sfxhash_maxdepth SFXHASH t  ) 
 

Get some hash table statistics. NOT FOR REAL TIME USE.

Parameters:
t SFXHASH table pointer
filled how many
Returns:
max depth of the table

Definition at line 958 of file sfxhash.c.

References _sfxhash_node::next, _sfxhash::nrows, NULL, and _sfxhash::table.

Referenced by flowcache_stats().

void* sfxhash_mru SFXHASH t  ) 
 

Return the most recently used data from the global list

Parameters:
t SFXHASH table pointer
Returns:
void* valid pointer to the users data
Return values:
0 node not found

Definition at line 875 of file sfxhash.c.

References _sfxhash_node::data, NULL, and sfxhash_ghead().

Referenced by flowcache_mru(), ps_tracker_get(), PurgeSessionCache(), scoreboard_mru(), and server_stats_add_ipv4().

SFXHASH_NODE* sfxhash_mru_node SFXHASH t  ) 
 

Return the most recently used node from the global list

Parameters:
t SFXHASH table pointer
Returns:
SFXHASH_NODE* valid pointer to a node
Return values:
0 node not found

Definition at line 916 of file sfxhash.c.

References NULL, and sfxhash_ghead().

SFXHASH* sfxhash_new int  nrows,
int  keysize,
int  datasize,
int  maxmem,
int  anr_flag,
int(*)(void *key, void *data)  anrfree,
int(*)(void *key, void *data)  usrfree,
int  recycle_flag
 

Create a new hash table

By default, this will "splay" nodes to the top of a free list.

Parameters:
nrows number of rows in hash table
keysize key size in bytes, same for all keys
datasize datasize in bytes, zero indicates user manages data
maxmem maximum memory to use in bytes
anr_flag Automatic Node Recovery boolean flag
anrfree users Automatic Node Recovery memory release function
usrfree users standard memory release function
Returns:
SFXHASH*
Return values:
0 out of memory
!0 Valid SFXHASH pointer

Definition at line 175 of file sfxhash.c.

References _sfxhash::anr_count, _sfxhash::anr_flag, _sfxhash::anr_tries, _sfxhash::anrfree, calcNextPrime(), _sfxhash::cnode, _sfxhash::count, _sfxhash::crow, _sfxhash::datasize, _sfxhash::find_fail, _sfxhash::find_success, _sfxhash::ghead, _sfxhash::gtail, _sfxhash::keysize, _sfxhash::mc, MEMCAP::memused, MEMCAP::nblocks, _sfxhash::nrows, _sfxhash::overhead_blocks, _sfxhash::overhead_bytes, _sfxhash::recycle_nodes, s_malloc(), _sfxhash::sfhashfcn, sfhashfcn_new(), sfmemcap_init(), _sfxhash::splay, _sfxhash::table, and _sfxhash::usrfree.

Referenced by flowcache_init(), Frag3GlobalInit(), InitSessionCache(), ps_init(), scoreboard_init(), server_stats_init(), sfthd_new(), and ut_init().

unsigned sfxhash_overhead_blocks SFXHASH t  ) 
 

Get the # of overhead blocks

Parameters:
t SFXHASH table pointer

Definition at line 376 of file sfxhash.c.

References _sfxhash::overhead_blocks.

Referenced by flowcache_overhead_blocks().

unsigned sfxhash_overhead_bytes SFXHASH t  ) 
 

Get the # of overhead bytes

Parameters:
t SFXHASH table pointer

Definition at line 365 of file sfxhash.c.

References _sfxhash::overhead_bytes.

Referenced by flowcache_overhead_bytes(), scoreboard_overhead_bytes(), scoreboard_stats(), server_stats_overhead_bytes(), and ut_overhead_bytes().

int sfxhash_remove SFXHASH t,
void *  key
 

Remove a Key + Data Pair from the table.

Parameters:
t SFXHASH table pointer
key users key pointer
Returns:
0 success
Return values:
!0 failed

Definition at line 1019 of file sfxhash.c.

References _SFHASHFCN::hash_fcn, index, _sfxhash_node::key, _SFHASHFCN::keycmp_fcn, _sfxhash::keysize, _sfxhash_node::next, _sfxhash::nrows, _sfxhash::sfhashfcn, SFXHASH_ERR, sfxhash_free_node(), and _sfxhash::table.

Referenced by flowcache_releaseflow(), Frag3RemoveTracker(), RemoveSessionFromHashTable(), scoreboard_remove(), and server_stats_remove_ipv4().

int sfxhash_set_keyops SFXHASH h,
unsigned(*)(SFHASHFCN *p, unsigned char *d, int n)  hash_fcn,
int(*)(const void *s1, const void *s2, size_t n)  keycmp_fcn
 

Make sfhashfcn use a separate set of operators for the backend.

Parameters:
h sfhashfcn ptr
hash_fcn user specified hash function
keycmp_fcn user specified key comparisoin function

Definition at line 1135 of file sfxhash.c.

References _sfxhash::sfhashfcn, and sfhashfcn_set_keyops().

Referenced by flowcache_init().

void sfxhash_splaymode SFXHASH t,
int  n
 

Set Splay mode : Splays nodes to front of list on each access

Parameters:
t SFXHASH table pointer
n boolean flag toggles splaying of hash nodes

Definition at line 255 of file sfxhash.c.

References _sfxhash::splay.


Generated on Sun May 14 14:51:27 2006 by  doxygen 1.4.2