lib: add hash table
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
a70797d6ad
commit
0aec18db63
3 changed files with 157 additions and 0 deletions
28
include/lib/hashchain.h
Normal file
28
include/lib/hashchain.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _ht_H_
|
||||
#define _ht_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
typedef struct ht_entry {
|
||||
char *key;
|
||||
union {
|
||||
void *ptr;
|
||||
u64 val;
|
||||
};
|
||||
struct ht_entry *next;
|
||||
} ht_entry_t;
|
||||
|
||||
typedef struct {
|
||||
ht_entry_t **buckets;
|
||||
size_t capacity;
|
||||
size_t size;
|
||||
} ht_t;
|
||||
|
||||
ht_t *ht_create(size_t capacity);
|
||||
void ht_destroy(ht_t *ht);
|
||||
int ht_insert(ht_t *ht, const char *key, void *value);
|
||||
void *ht_lookup(ht_t *ht, const char *key);
|
||||
int ht_delete(ht_t *ht, const char *key);
|
||||
|
||||
#endif /* _ht_H_ */
|
||||
Loading…
Reference in a new issue