lib: add hash table

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-08-12 20:06:48 -04:00
commit 0aec18db63
Signed by: michaelsshaw
GPG key ID: 5A5E0FB20708A9E7
3 changed files with 157 additions and 0 deletions

28
include/lib/hashchain.h Normal file
View 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_ */