-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtern.h
55 lines (47 loc) · 1.81 KB
/
tern.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Copyright 2013 Michael Pavone
This file is part of BlastEm.
BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
*/
#ifndef TERN_H_
#define TERN_H_
#include <stdint.h>
#define MAX_INT_KEY_SIZE (sizeof(uint32_t) + 2)
typedef union {
void *ptrval;
intptr_t intval;
} tern_val;
typedef struct tern_node {
struct tern_node *left;
union {
struct tern_node *next;
tern_val value;
} straight;
struct tern_node *right;
char el;
uint8_t valtype;
} tern_node;
enum {
TVAL_NONE=0,
TVAL_INT,
TVAL_PTR,
TVAL_NODE
};
typedef void (*iter_fun)(char *key, tern_val val, uint8_t valtype, void *data);
tern_node * tern_insert(tern_node * head, char const * key, tern_val value, uint8_t valtype);
uint8_t tern_find(tern_node * head, char const * key, tern_val *ret);
tern_node * tern_find_prefix(tern_node * head, char const * key);
intptr_t tern_find_int(tern_node * head, char const * key, intptr_t def);
tern_node * tern_insert_int(tern_node * head, char const * key, intptr_t value);
void * tern_find_ptr_default(tern_node * head, char const * key, void * def);
void * tern_find_ptr(tern_node * head, char const * key);
tern_node *tern_find_node(tern_node *head, char const *key);
tern_val tern_find_path_default(tern_node *head, char const *key, tern_val def, uint8_t req_valtype);
tern_val tern_find_path(tern_node *head, char const *key, uint8_t valtype);
tern_node * tern_insert_ptr(tern_node * head, char const * key, void * value);
tern_node * tern_insert_node(tern_node *head, char const *key, tern_node *value);
uint32_t tern_count(tern_node *head);
void tern_foreach(tern_node *head, iter_fun fun, void *data);
char * tern_int_key(uint32_t key, char * buf);
void tern_free(tern_node *head);
#endif //TERN_H_