]>
Commit | Line | Data |
---|---|---|
43ae1d95 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 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" |
43ae1d95 | 10 | #include "Trie.h" |
924f73bc | 11 | #include "TrieCharTransform.h" |
602d9612 | 12 | #include "TrieNode.h" |
43ae1d95 | 13 | |
7d341c2c FC |
14 | #if HAVE_UNISTD_H |
15 | #include <unistd.h> | |
ea2728e3 AJ |
16 | #endif |
17 | ||
aee3523a | 18 | Trie::Trie(TrieCharTransform *aTransform) : head(nullptr), transform(aTransform) |
43ae1d95 | 19 | {} |
20 | ||
6ca34f6f | 21 | Trie::~Trie() |
43ae1d95 | 22 | { |
23 | delete head; | |
924f73bc | 24 | delete transform; |
43ae1d95 | 25 | } |
26 | ||
43ae1d95 | 27 | bool |
6ca34f6f | 28 | Trie::add(char const *aString, size_t theLength, void *privatedata) |
43ae1d95 | 29 | { |
30 | if (!privatedata) | |
31 | return false; | |
32 | ||
33 | if (head) { | |
6ca34f6f | 34 | if (find(aString, theLength)) |
43ae1d95 | 35 | return false; |
36 | ||
6ca34f6f | 37 | return head->add(aString, theLength, privatedata, transform); |
43ae1d95 | 38 | } |
39 | ||
40 | head = new TrieNode; | |
41 | ||
6ca34f6f | 42 | return head->add(aString, theLength, privatedata, transform); |
43ae1d95 | 43 | } |
f53969cc | 44 |