]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/libTrie/Trie.cc
SourceFormat Enforcement
[thirdparty/squid.git] / lib / libTrie / Trie.cc
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #include "squid.h"
10 #include "Trie.h"
11 #include "TrieCharTransform.h"
12 #include "TrieNode.h"
13
14 #if HAVE_UNISTD_H
15 #include <unistd.h>
16 #endif
17
18 Trie::Trie(TrieCharTransform *aTransform) : head(0) , transform(aTransform)
19 {}
20
21 Trie::~Trie()
22 {
23 delete head;
24 delete transform;
25 }
26
27 bool
28 Trie::add(char const *aString, size_t theLength, void *privatedata)
29 {
30 if (!privatedata)
31 return false;
32
33 if (head) {
34 if (find(aString, theLength))
35 return false;
36
37 return head->add(aString, theLength, privatedata, transform);
38 }
39
40 head = new TrieNode;
41
42 return head->add(aString, theLength, privatedata, transform);
43 }
44