From c9bee1793c770412c4030c6fe56f2fd255c82c8c Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 20 Jul 2015 07:41:25 -0500 Subject: [PATCH] WHoops! --- include/patty/dict.h | 46 ++++++++++++++++++++++++++++++++++++++++++++ include/patty/hash.h | 11 +++++++++++ 2 files changed, 57 insertions(+) create mode 100644 include/patty/dict.h create mode 100644 include/patty/hash.h diff --git a/include/patty/dict.h b/include/patty/dict.h new file mode 100644 index 0000000..ae2bccb --- /dev/null +++ b/include/patty/dict.h @@ -0,0 +1,46 @@ +#ifndef _PATTY_DICT_H +#define _PATTY_DICT_H + +#include +#include + +#include + +#define PATTY_DICT_BUCKET_SIZE 16 + +typedef struct _patty_dict_slot { + uint32_t hash; + void * key; + size_t keysz; + void * value; + + struct _patty_dict_slot * next; +} patty_dict_slot; + +typedef struct _patty_dict_bucket { + patty_dict_slot slots[16]; +} patty_dict_bucket; + +typedef struct _patty_dict { + patty_dict_bucket bucket; +} patty_dict; + +patty_dict *patty_dict_new(); + +patty_dict_slot *patty_dict_slot_find(patty_dict *dict, uint32_t hash); + +typedef int (*patty_dict_callback)( + void * key, + size_t keysz, + void * value, + void * ctx); + +int patty_dict_each(patty_dict *dict, patty_dict_callback callback, void *ctx); + +void *patty_dict_get(patty_dict *dict, void *key, size_t keysz); + +void *patty_dict_set(patty_dict *dict, void *key, size_t keysz, void *value); + +void patty_dict_destroy(patty_dict *dict); + +#endif /* _PATTY_DICT_H */ diff --git a/include/patty/hash.h b/include/patty/hash.h new file mode 100644 index 0000000..280bb91 --- /dev/null +++ b/include/patty/hash.h @@ -0,0 +1,11 @@ +#ifndef _PATTY_HASH_H +#define _PATTY_HASH_H + +#include +#include + +#define PATTY_DICT_BUCKET_SIZE 16 + +uint32_t patty_hash(void *key, size_t size); + +#endif /* _PATTY_HASH_H */