]> git.ipfire.org Git - thirdparty/squid.git/blame - lib/libTrie/Trie.cc
SourceFormat Enforcement
[thirdparty/squid.git] / lib / libTrie / Trie.cc
CommitLineData
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
99742866 20#include "squid.h"
43ae1d95 21#include "Trie.h"
32d002cb 22#if HAVE_UNISTD_H
43ae1d95 23#include <unistd.h>
24#endif
924f73bc 25#include "TrieCharTransform.h"
602d9612 26#include "TrieNode.h"
43ae1d95 27
81914193 28#if !_USE_INLINE_
ea2728e3
AJ
29#include "Trie.cci"
30#endif
31
6ca34f6f 32Trie::Trie(TrieCharTransform *aTransform) : head(0) , transform(aTransform)
43ae1d95 33{}
34
6ca34f6f 35extern "C" void *TrieCreate()
43ae1d95 36{
37 return new Trie;
38}
39
6ca34f6f 40Trie::~Trie()
43ae1d95 41{
42 delete head;
924f73bc 43 delete transform;
43ae1d95 44}
45
6ca34f6f 46extern "C" void TrieDestroy(void *aTrie)
43ae1d95 47{
48 delete (Trie *)aTrie;
49}
50
6ca34f6f 51extern "C" void *TrieFind(void *aTrie, char const *aString, size_t theLength)
43ae1d95 52{
6ca34f6f 53 return ((Trie *)aTrie)->find(aString, theLength);
43ae1d95 54}
55
56bool
6ca34f6f 57Trie::add(char const *aString, size_t theLength, void *privatedata)
43ae1d95 58{
59 if (!privatedata)
60 return false;
61
62 if (head) {
6ca34f6f 63 if (find(aString, theLength))
43ae1d95 64 return false;
65
6ca34f6f 66 return head->add(aString, theLength, privatedata, transform);
43ae1d95 67 }
68
69 head = new TrieNode;
70
6ca34f6f 71 return head->add(aString, theLength, privatedata, transform);
43ae1d95 72}
73
6ca34f6f 74extern "C" int TrieAdd(void *aTrie, char const *aString, size_t theLength, void *privatedata)
43ae1d95 75{
76
6ca34f6f 77 return ((Trie *)aTrie)->add(aString, theLength, privatedata);
43ae1d95 78}