This commit is contained in:
XANTRONIX Development 2015-07-20 07:41:25 -05:00
parent 03742ae281
commit c9bee1793c
2 changed files with 57 additions and 0 deletions

46
include/patty/dict.h Normal file
View file

@ -0,0 +1,46 @@
#ifndef _PATTY_DICT_H
#define _PATTY_DICT_H
#include <stdint.h>
#include <sys/types.h>
#include <patty/hash.h>
#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 */

11
include/patty/hash.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef _PATTY_HASH_H
#define _PATTY_HASH_H
#include <stdint.h>
#include <sys/types.h>
#define PATTY_DICT_BUCKET_SIZE 16
uint32_t patty_hash(void *key, size_t size);
#endif /* _PATTY_HASH_H */