]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/libTrie/TrieNode.h
LibTrie refactro: remove sub-configure invocation
[thirdparty/squid.git] / lib / libTrie / TrieNode.h
1 /*
2 * Copyright (c) 2002,2003 Robert Collins <rbtcollins@hotmail.com>
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.
8 *
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.
13 *
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_TRIENODE_H
21 #define LIBTRIE_TRIENODE_H
22
23 /* This is an internal header for libTrie.
24 * libTrie provides both C and C++
25 * bindings.
26 * libTrie itself is written in C++.
27 * For C bindings see Trei.h
28 */
29
30 /* C bindings */
31 #ifndef __cplusplus
32
33 /* C++ bindings */
34 #else
35 #include <sys/types.h>
36 #include <utility>
37
38 /* MinGW needs NULL definition */
39 #ifndef NULL
40 #define NULL 0
41 #endif
42
43 /* TODO: parameterize this to be more generic -
44 * i.e. M-ary internal node sizes etc
45 */
46
47 class TrieCharTransform;
48
49 class TrieNode
50 {
51
52 public:
53 TrieNode();
54 ~TrieNode();
55 TrieNode(TrieNode const &);
56 TrieNode &operator= (TrieNode const &);
57
58 /* Find a string.
59 * If found, return the private data.
60 * If not found, return NULL.
61 */
62 _SQUID_INLINE_ void *find (char const *, size_t, TrieCharTransform *, bool const prefix) const;
63
64 /* Add a string.
65 * returns false if the string is already
66 * present or can't be added.
67 */
68
69 bool add
70 (char const *, size_t, void *, TrieCharTransform *);
71
72 private:
73 /* 256-way Trie */
74 /* The char index into internal is an
75 * 8-bit prefix to a string in the trie.
76 * internal[0] is the terminal node for
77 * a string and may not be used
78 */
79 TrieNode * internal[256];
80
81 /* If a string ends here, non NULL */
82 void *_privateData;
83 };
84
85 #endif /* __cplusplus */
86
87 #if _USE_INLINE_
88 #include "TrieNode.cci"
89 #endif
90
91 #endif /* LIBTRIE_TRIENODE_H */