~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to lib/libTrie/src/TrieNode.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "TrieNode.h"
 
21
#include "TrieCharTransform.h"
 
22
#ifdef HAVE_UNISTD_H
 
23
#include <unistd.h>
 
24
#endif
 
25
 
 
26
TrieNode::TrieNode () : _privateData (NULL)
 
27
{
 
28
    for (int i = 0; i < 256; ++i)
 
29
        internal[i] = NULL;
 
30
}
 
31
 
 
32
TrieNode::~TrieNode ()
 
33
{
 
34
    for (int i = 0; i < 256; ++i)
 
35
        delete internal[i];
 
36
}
 
37
 
 
38
/* as for find */
 
39
bool
 
40
 
 
41
TrieNode::add
 
42
    (char const *aString, size_t theLength, void *privatedata, TrieCharTransform *transform)
 
43
{
 
44
    /* We trust that privatedata and existant keys have already been checked */
 
45
 
 
46
    if (theLength) {
 
47
        int index = transform ? (*transform) (*aString): *aString;
 
48
 
 
49
        if (!internal[index])
 
50
            internal[index] = new TrieNode;
 
51
 
 
52
        return internal[index]->add
 
53
               (aString + 1, theLength - 1, privatedata, transform);
 
54
    } else {
 
55
        /* terminal node */
 
56
 
 
57
        if (_privateData)
 
58
            return false;
 
59
 
 
60
        _privateData = privatedata;
 
61
 
 
62
        return true;
 
63
    }
 
64
}
 
65
 
 
66
#ifndef _USE_INLINE_
 
67
#include "TrieNode.cci"
 
68
#endif