]>
Commit | Line | Data |
---|---|---|
43ae1d95 | 1 | /* |
924f73bc | 2 | * Copyright (c) 2002,2003 Robert Collins <rbtcollins@hotmail.com> |
43ae1d95 | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
26ac0430 | 8 | * |
43ae1d95 | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
26ac0430 | 13 | * |
43ae1d95 | 14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
17 | * | |
18 | */ | |
19 | ||
20 | #ifndef LIBTRIE_SQUID_H | |
21 | #define LIBTRIE_SQUID_H | |
22 | ||
23 | /* This is the header for libTrie. | |
26ac0430 | 24 | * libTrie provides both C and C++ |
43ae1d95 | 25 | * bindings. libtrie itself is written in C++. |
26 | */ | |
27 | ||
43ae1d95 | 28 | #if HAVE_SYS_TYPES_H |
29 | #include <sys/types.h> | |
30 | #endif | |
31 | ||
32 | /* C bindings */ | |
33 | #ifndef __cplusplus | |
34 | ||
924f73bc | 35 | /* TODO: provide parameterisation for C bindings */ |
aa625860 | 36 | void *TrieCreate (void); |
43ae1d95 | 37 | void TrieDestroy (void *); |
38 | void *TrieFind (void *, char const *, size_t); | |
39 | int TrieAdd (void *, char const *, size_t, void *); | |
40 | ||
41 | /* C++ bindings */ | |
42 | #else | |
43 | ||
fdbe8c51 | 44 | /* MinGW needs NULL definition */ |
45 | #ifndef NULL | |
46 | #define NULL 0 | |
47 | #endif | |
48 | ||
924f73bc | 49 | class TrieCharTransform; |
50 | ||
43ae1d95 | 51 | class TrieNode; |
52 | ||
53 | /* TODO: parameterize this to be more generic - | |
54 | * i.e. M-ary internal node sizes etc | |
55 | */ | |
56 | ||
57 | class Trie | |
58 | { | |
59 | ||
60 | public: | |
924f73bc | 61 | Trie(TrieCharTransform *aTransform = 0); |
43ae1d95 | 62 | ~Trie(); |
63 | Trie (Trie const &); | |
64 | Trie &operator= (Trie const &); | |
65 | ||
66 | /* Find an exact match in the trie. | |
67 | * If found, return the private data. | |
68 | * If not found, return NULL. | |
69 | */ | |
70 | _SQUID_INLINE_ void *find (char const *, size_t); | |
71 | /* find any element of the trie in the buffer from the | |
72 | * beginning thereof | |
73 | */ | |
74 | _SQUID_INLINE_ void *findPrefix (char const *, size_t); | |
75 | ||
76 | /* Add a string. | |
77 | * returns false if the string is already | |
78 | * present or cannot be added. | |
79 | */ | |
80 | ||
ea2728e3 | 81 | bool add(char const *, size_t, void *); |
43ae1d95 | 82 | |
83 | private: | |
84 | TrieNode *head; | |
924f73bc | 85 | |
86 | /* transfor each 8 bits in the element */ | |
87 | TrieCharTransform *transform; | |
43ae1d95 | 88 | }; |
89 | ||
90 | #endif /* __cplusplus */ | |
91 | ||
73862432 | 92 | #if _USE_INLINE_ |
43ae1d95 | 93 | #include "Trie.cci" |
94 | #endif | |
95 | ||
96 | #endif /* LIBTRIE_SQUID_H */ |