]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/libTrie/Trie.cc
Merge from trunk
[thirdparty/squid.git] / lib / libTrie / Trie.cc
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 #include "squid.h"
21 #include "Trie.h"
22 #include "TrieCharTransform.h"
23 #include "TrieNode.h"
24
25 #if HAVE_UNISTD_H
26 #include <unistd.h>
27 #endif
28
29 Trie::Trie(TrieCharTransform *aTransform) : head(0) , transform(aTransform)
30 {}
31
32 Trie::~Trie()
33 {
34 delete head;
35 delete transform;
36 }
37
38 bool
39 Trie::add(char const *aString, size_t theLength, void *privatedata)
40 {
41 if (!privatedata)
42 return false;
43
44 if (head) {
45 if (find(aString, theLength))
46 return false;
47
48 return head->add(aString, theLength, privatedata, transform);
49 }
50
51 head = new TrieNode;
52
53 return head->add(aString, theLength, privatedata, transform);
54 }