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