mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 20:58:22 +00:00
trie: support preallocations
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
#ifndef _TRIE_H
|
||||
#define _TRIE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define TRIE_BITS 6
|
||||
#define TRIE_NODE_COUNT (1 << TRIE_BITS)
|
||||
#define TRIE_MAX_DEPTH (2 * ((64 + TRIE_BITS - 1) / TRIE_BITS) - 1)
|
||||
|
||||
typedef struct trie_node trie_node_t;
|
||||
struct trie_node {
|
||||
@@ -15,6 +17,11 @@ struct trie_node {
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
size_t allocation_count;
|
||||
trie_node_t *allocations[TRIE_MAX_DEPTH];
|
||||
} trie_preallocation_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t height;
|
||||
union {
|
||||
@@ -26,7 +33,10 @@ typedef struct {
|
||||
typedef void (trie_iterate_fn_t)(void *item);
|
||||
|
||||
void trie_init(trie_t *trie);
|
||||
trie_preallocation_t *trie_preallocate(void);
|
||||
int trie_insert(trie_t *trie, uint64_t key, void *value);
|
||||
int trie_insert_preallocated(trie_t *trie, uint64_t key, void *value, trie_preallocation_t *preallocation);
|
||||
void trie_free_preallocation(trie_preallocation_t *preallocation);
|
||||
int trie_lookup(trie_t *trie, uint64_t key, void **ret);
|
||||
int trie_remove(trie_t *trie, uint64_t key);
|
||||
void trie_truncate(trie_t *trie, uint64_t max_key);
|
||||
|
||||
Reference in New Issue
Block a user