68 lines
1.9 KiB
C
68 lines
1.9 KiB
C
#ifndef INCLUDED_C_HASHST_H
|
|||
|
|
#define INCLUDED_C_HASHST_H
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_TYPES_H
|
||
|
|
#include <c_Types.h>
|
||
|
|
#endif /*INCLUDED_C_TYPES_H*/
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_PTRBAG_H
|
||
|
|
#include <c_PtrBag.h>
|
||
|
|
#endif /*INCLUDED_C_PTRBAG_H*/
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
|
||
|
|
typedef struct c_HashKeyOps_t {
|
||
|
|
uint32_t (*hash)(const void *data, void *arg);
|
||
|
|
void* (*cp)(const void *data, void *arg);
|
||
|
|
void (*free)(void *data, void *arg);
|
||
|
|
bool (*eq)(const void *data1, const void *data2, void *arg);
|
||
|
|
void *arg;
|
||
|
|
} c_HashKeyOps_t;
|
||
|
|
|
||
|
|
typedef struct c_HashValOps_t {
|
||
|
|
void* (*cp)(const void *data, void *arg);
|
||
|
|
void (*free)(void *data, void *arg);
|
||
|
|
bool (*eq)(const void *data1, const void *data2, void *arg);
|
||
|
|
void *arg;
|
||
|
|
} c_HashValOps_t;
|
||
|
|
|
||
|
|
typedef struct c_HashSTNode_t {
|
||
|
|
uint32_t hash;
|
||
|
|
void* key;
|
||
|
|
void* val;
|
||
|
|
}c_HashSTNode_t;
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
c_PtrBag_t** buckets;
|
||
|
|
c_size_t capacity;
|
||
|
|
c_size_t size;
|
||
|
|
c_HashKeyOps_t key_ops;
|
||
|
|
c_HashValOps_t val_ops;
|
||
|
|
c_Allocator_t allocator;
|
||
|
|
}c_HashST_t;
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
c_err_t c_HashST_Init(c_HashST_t* self, c_size_t capacity, c_HashKeyOps_t key_ops, c_HashValOps_t val_ops, c_Allocator_t* allocator);
|
||
|
|
|
||
|
|
void c_HashST_Destroy(c_HashST_t* self);
|
||
|
|
|
||
|
|
c_err_t c_HashST_Resize(c_HashST_t* self, c_size_t new_capacity);
|
||
|
|
|
||
|
|
c_err_t c_HashST_Put(c_HashST_t* self, const void* key, const void* val);
|
||
|
|
|
||
|
|
void* c_HashST_Get(c_HashST_t* self, const void* key);
|
||
|
|
|
||
|
|
c_err_t c_HashST_Remove(c_HashST_t* self, const void* key);
|
||
|
|
|
||
|
|
bool c_HashST_Contains(c_HashST_t* self, const void* key);
|
||
|
|
|
||
|
|
c_size_t c_HashST_NumCol(c_HashST_t* self);
|
||
|
|
|
||
|
|
void c_HashST_ForEach(c_HashST_t* self, void (*apply)(c_HashSTNode_t* node, void* args), void* args);
|
||
|
|
|
||
|
|
#endif /*INCLUDED_C_HASHST_H*/
|