]>
Commit | Line | Data |
---|---|---|
43ae1d95 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
43ae1d95 | 3 | * |
dc4eb86a AJ |
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. | |
43ae1d95 | 7 | */ |
8 | ||
99742866 | 9 | #include "squid.h" |
924f73bc | 10 | #include "TrieCharTransform.h" |
602d9612 | 11 | #include "TrieNode.h" |
32d002cb | 12 | #if HAVE_UNISTD_H |
43ae1d95 | 13 | #include <unistd.h> |
14 | #endif | |
43ae1d95 | 15 | |
6ca34f6f | 16 | TrieNode::TrieNode() : _privateData(NULL) |
43ae1d95 | 17 | { |
18 | for (int i = 0; i < 256; ++i) | |
19 | internal[i] = NULL; | |
20 | } | |
21 | ||
6ca34f6f | 22 | TrieNode::~TrieNode() |
43ae1d95 | 23 | { |
24 | for (int i = 0; i < 256; ++i) | |
25 | delete internal[i]; | |
26 | } | |
27 | ||
28 | /* as for find */ | |
29 | bool | |
6ca34f6f | 30 | TrieNode::add(char const *aString, size_t theLength, void *privatedata, TrieCharTransform *transform) |
43ae1d95 | 31 | { |
2f8abb64 | 32 | /* We trust that privatedata and existent keys have already been checked */ |
43ae1d95 | 33 | |
34 | if (theLength) { | |
6ca34f6f | 35 | int index = transform ? (*transform)(*aString): *aString; |
43ae1d95 | 36 | |
924f73bc | 37 | if (!internal[index]) |
43ae1d95 | 38 | internal[index] = new TrieNode; |
43ae1d95 | 39 | |
6ca34f6f | 40 | return internal[index]->add(aString + 1, theLength - 1, privatedata, transform); |
43ae1d95 | 41 | } else { |
42 | /* terminal node */ | |
43 | ||
44 | if (_privateData) | |
45 | return false; | |
46 | ||
47 | _privateData = privatedata; | |
48 | ||
49 | return true; | |
50 | } | |
51 | } | |
f53969cc | 52 |