-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrie.h
59 lines (43 loc) · 1.5 KB
/
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
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
56
57
58
59
#ifndef TRIE_H
#define TRIE_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ARRAY_SIZE(a) sizeof(a)/sizeof(a[0])
// Alphabet size (# of symbols)
#define ALPHABET_SIZE (26)
#define MAX_KEY 100
// Converts key current character into index
// use only 'a' through 'z' and lower case
//#define CHAR_TO_INDEX(c) ((int)c - (int)'a')
// trie node
typedef struct TrieNode {
struct TrieNode *children[ALPHABET_SIZE];
char color;
// isEndOfWord is true if the node represents
// end of a word
char isEndOfWord;
} TrieNode;
// Returns new trie node (initialized to NULLs)
TrieNode *getNode(void);
// If not present, inserts key into trie
// If the key is prefix of trie node, just marks leaf node
void insert(TrieNode *root, const char *key, char color);
// Returns true if key presents in trie, else false
int search(TrieNode *root, const char *key, char *color);
// trie node
typedef struct TrieNode_c {
struct TrieNode_c *children[ALPHABET_SIZE];
int lower, upper;
// isEndOfWord is true if the node represents
// end of a word
char isEndOfWord;
} TrieNode_c;
// Returns new trie node (initialized to NULLs)
TrieNode_c *codebaseNode(void);
// If not present, inserts key into trie
// If the key is prefix of trie node, just marks leaf node
void insert_in_codebase(TrieNode_c *root, const char *key, int lower, int upper);
// Returns true if key presents in trie, else false
int search_in_codebase(TrieNode_c *root, const char *key, int *lower, int *upper);
#endif