2008-11-26 22:37:49 +00:00
|
|
|
#ifndef STASIS_LHTABLE_H
|
|
|
|
#define STASIS_LHTABLE_H
|
2006-05-24 02:23:58 +00:00
|
|
|
|
2013-02-09 02:51:38 +00:00
|
|
|
#include <stasis/common.h>
|
|
|
|
|
|
|
|
BEGIN_C_DECLS
|
|
|
|
|
2009-08-14 06:31:13 +00:00
|
|
|
#ifndef LH_ENTRY
|
2006-05-24 02:23:58 +00:00
|
|
|
#define LH_ENTRY(foo) lh##foo
|
2009-08-14 06:31:13 +00:00
|
|
|
#endif // LH_ENTRY
|
2006-05-24 02:23:58 +00:00
|
|
|
|
|
|
|
typedef void LH_ENTRY(value_t);
|
|
|
|
typedef void LH_ENTRY(key_t);
|
|
|
|
|
|
|
|
struct LH_ENTRY(pair_t) {
|
|
|
|
const LH_ENTRY(key_t) * key;
|
|
|
|
int keyLength;
|
|
|
|
LH_ENTRY(value_t) * value;
|
|
|
|
struct LH_ENTRY(pair_t) * next;
|
|
|
|
};
|
|
|
|
|
2009-08-14 06:31:13 +00:00
|
|
|
#ifndef PBL_COMPAT
|
2006-05-24 02:23:58 +00:00
|
|
|
#define PBL_COMPAT 1
|
2009-08-14 06:31:13 +00:00
|
|
|
#endif
|
2006-05-24 02:23:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@todo The current implementation (and interface) hardcodes the idea
|
|
|
|
that (key,value) pairs are inserted into the hashtable. It would
|
|
|
|
be better if it were more flexible. Something like redblack.h
|
|
|
|
would be nice, but that requires complex macros, code generation,
|
|
|
|
etc...
|
|
|
|
*/
|
|
|
|
struct LH_ENTRY(table) * LH_ENTRY(create)(int initialSize);
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return 0 if item was not already in hashtable, pointer to old
|
|
|
|
value otherwise.
|
|
|
|
*/
|
|
|
|
LH_ENTRY(value_t) * LH_ENTRY(insert) (struct LH_ENTRY(table) * table,
|
|
|
|
const LH_ENTRY(key_t) * key, int len,
|
|
|
|
LH_ENTRY(value_t) * value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return 0 if item not found
|
|
|
|
*/
|
|
|
|
LH_ENTRY(value_t) * LH_ENTRY(remove) (struct LH_ENTRY(table) * table,
|
|
|
|
const LH_ENTRY(key_t) * key, int len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return 0 if item not found
|
|
|
|
*/
|
|
|
|
LH_ENTRY(value_t) * LH_ENTRY(find) (struct LH_ENTRY(table) * table,
|
|
|
|
const LH_ENTRY(key_t) * key, int len);
|
|
|
|
|
|
|
|
void LH_ENTRY(destroy) (struct LH_ENTRY(table) * table);
|
|
|
|
|
|
|
|
struct LH_ENTRY(list) {
|
|
|
|
const struct LH_ENTRY(table) * table;
|
|
|
|
struct LH_ENTRY(pair_t) * currentPair;
|
|
|
|
struct LH_ENTRY(pair_t) * nextPair;
|
|
|
|
long currentBucket;
|
|
|
|
};
|
|
|
|
|
2006-08-10 23:43:53 +00:00
|
|
|
/**
|
|
|
|
Print out stats regarding the lhtable implementation. Currently,
|
|
|
|
only prints anything if MEASURE_GLOBAL_BUCKET_LENGTH is defined.
|
|
|
|
*/
|
|
|
|
void LH_ENTRY(stats)();
|
|
|
|
|
2006-05-24 02:23:58 +00:00
|
|
|
void LH_ENTRY(openlist)(const struct LH_ENTRY(table) * table,
|
|
|
|
struct LH_ENTRY(list) * newList);
|
|
|
|
/**
|
|
|
|
@return 0 at end of list.
|
|
|
|
*/
|
|
|
|
const struct LH_ENTRY(pair_t)* LH_ENTRY(readlist)(struct LH_ENTRY(list)* list);
|
|
|
|
void LH_ENTRY(closelist)(struct LH_ENTRY(list) * list);
|
2008-11-26 22:37:49 +00:00
|
|
|
|
2013-02-09 02:51:38 +00:00
|
|
|
END_C_DECLS
|
|
|
|
|
2008-11-26 22:37:49 +00:00
|
|
|
#endif // STASIS_LHTABLE_H
|