-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrie.c
39 lines (35 loc) · 814 Bytes
/
trie.c
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
/*
* @Description:
* @LastEditors: hsjfans
* @Email: [email protected]
* @Date: 2019-05-09 11:31:27
* @LastEditTime: 2019-05-13 11:16:42
*/
#include "include/trie.h"
#include <stdlib.h>
// the trie node define
struct trie_node
{
int code; // the code of element
int depth; // depth is the level of node
int left; // the left limit
int right; // the right limit
};
// the trie entity define
// base[s] + c = t
// check[t] = s
struct trie
{
// two array have same capacity
int *base;
int *check;
boolean *use;
int cap;
};
void extend_capacity(Trie t, int new_cap)
{
t->base = realloc(t->base, new_cap * sizeof(int));
t->check = realloc(t->check, new_cap * sizeof(int));
t->use = realloc(t->use, new_cap * sizeof(boolean));
t->cap = new_cap;
}