diff options
| author | Ibrahim Muftee <ibrahim@muftee.net> | 2026-08-02 23:08:35 -0500 |
|---|---|---|
| committer | Ibrahim Muftee <ibrahim@muftee.net> | 2026-08-02 23:09:17 -0500 |
| commit | e70d4061e7bd9c376dd4d92df91ed0cef022b426 (patch) | |
| tree | 4959f5a6a76de7773b330085e86d50570b583f97 | |
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | inc/kv.h | 19 | ||||
| -rw-r--r-- | src/kv.c | 16 | ||||
| -rw-r--r-- | src/main.c | 9 |
4 files changed, 45 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..36f971e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/* diff --git a/inc/kv.h b/inc/kv.h new file mode 100644 index 0000000..8db497a --- /dev/null +++ b/inc/kv.h @@ -0,0 +1,19 @@ +#ifndef KV_H +#define KV_H + +#include <stdlib.h> + +typedef struct { + char *key; + char *value; +} kv_entry_t; + +typedef struct { + size_t capacity; + size_t count; + kv_entry_t *entries; +} kv_t; + +kv_t *kv_init(size_t capacity); + +#endif diff --git a/src/kv.c b/src/kv.c new file mode 100644 index 0000000..d936cf0 --- /dev/null +++ b/src/kv.c @@ -0,0 +1,16 @@ +#include <kv.h> + +kv_t *kv_init(size_t capacity) { + if (capacity == 0) return NULL; + + kv_t *table = malloc(sizeof(kv_t)); + if (table == NULL) return NULL; + + table->capacity = capacity; + table->count = 0; + + table->entries = calloc(capacity, sizeof(kv_entry_t)); + if (table->entries == NULL) return NULL; + + return table; +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..033a1d0 --- /dev/null +++ b/src/main.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <kv.h> + +int main() { + kv_t *table = kv_init(3); + printf("%p\n", table); + + printf("%zu\n", table->capacity); +} |
