-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtrie.h
29 lines (22 loc) · 829 Bytes
/
trie.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
/* Copyright 2013 Bliksem Labs. See the LICENSE file at the top-level directory of this distribution and at https://github.com/bliksemlabs/rrrr/. */
#ifndef _TRIE_H_
#define _TRIE_H_
#define TRIE_SIZE 128
#define TRIE_SENTINEL 0
#include "tdata.h"
typedef struct _trie_t {
struct _trie_t *chars[TRIE_SIZE];
unsigned char node;
int32_t index;
} trie_t;
trie_t *trie_init(void);
void trie_add(trie_t *, char *);
uint32_t trie_exists(trie_t *, char *);
uint32_t trie_prefix(trie_t *, char *);
uint32_t trie_complete(trie_t *, char *, char *);
uint32_t trie_load(trie_t *, tdata_t *);
void trie_strip(trie_t *, char *, char *);
void trie_free(trie_t *);
#define trie_step(t,c) (t = (t == NULL || t->chars[c] == NULL ? NULL : t->chars[c]))
#define trie_word(t) (t != NULL && t->chars[TRIE_SENTINEL] != NULL)
#endif