HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Junxiao Shi | 2b73ca3 | 2014-11-17 19:16:08 -0700 | [diff] [blame] | 24 | */ |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 25 | |
| 26 | #include "name-tree.hpp" |
| 27 | #include "core/logger.hpp" |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 28 | #include "core/city-hash.hpp" |
Davide Pesavento | 52a18f9 | 2014-04-10 00:55:01 +0200 | [diff] [blame] | 29 | |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 30 | #include <boost/concept/assert.hpp> |
| 31 | #include <boost/concept_check.hpp> |
| 32 | #include <type_traits> |
| 33 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 34 | namespace nfd { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 35 | namespace name_tree { |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 36 | |
| 37 | NFD_LOG_INIT("NameTree"); |
| 38 | |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 39 | // http://en.cppreference.com/w/cpp/concept/ForwardIterator |
| 40 | BOOST_CONCEPT_ASSERT((boost::ForwardIterator<NameTree::const_iterator>)); |
| 41 | // boost::ForwardIterator follows SGI standard http://www.sgi.com/tech/stl/ForwardIterator.html, |
| 42 | // which doesn't require DefaultConstructible |
| 43 | #ifdef HAVE_IS_DEFAULT_CONSTRUCTIBLE |
| 44 | static_assert(std::is_default_constructible<NameTree::const_iterator>::value, |
| 45 | "NameTree::const_iterator must be default-constructible"); |
| 46 | #else |
| 47 | BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<NameTree::const_iterator>)); |
| 48 | #endif // HAVE_IS_DEFAULT_CONSTRUCTIBLE |
| 49 | |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 50 | class Hash32 |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 51 | { |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 52 | public: |
| 53 | static size_t |
| 54 | compute(const char* buffer, size_t length) |
| 55 | { |
| 56 | return static_cast<size_t>(CityHash32(buffer, length)); |
| 57 | } |
| 58 | }; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 59 | |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 60 | class Hash64 |
| 61 | { |
| 62 | public: |
| 63 | static size_t |
| 64 | compute(const char* buffer, size_t length) |
| 65 | { |
| 66 | return static_cast<size_t>(CityHash64(buffer, length)); |
| 67 | } |
| 68 | }; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 69 | |
Alexander Afanasyev | b755e9d | 2015-10-20 17:35:51 -0500 | [diff] [blame] | 70 | /// @cond NoDocumentation |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 71 | typedef boost::mpl::if_c<sizeof(size_t) >= 8, Hash64, Hash32>::type CityHash; |
Alexander Afanasyev | b755e9d | 2015-10-20 17:35:51 -0500 | [diff] [blame] | 72 | /// @endcond |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 73 | |
| 74 | // Interface of different hash functions |
| 75 | size_t |
| 76 | computeHash(const Name& prefix) |
| 77 | { |
| 78 | prefix.wireEncode(); // guarantees prefix's wire buffer is not empty |
| 79 | |
| 80 | size_t hashValue = 0; |
| 81 | size_t hashUpdate = 0; |
| 82 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 83 | for (Name::const_iterator it = prefix.begin(); it != prefix.end(); ++it) { |
| 84 | const char* wireFormat = reinterpret_cast<const char*>( it->wire() ); |
| 85 | hashUpdate = CityHash::compute(wireFormat, it->size()); |
| 86 | hashValue ^= hashUpdate; |
| 87 | } |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 88 | |
| 89 | return hashValue; |
| 90 | } |
| 91 | |
| 92 | std::vector<size_t> |
| 93 | computeHashSet(const Name& prefix) |
| 94 | { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 95 | prefix.wireEncode(); // guarantees prefix's wire buffer is not empty |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 96 | |
| 97 | size_t hashValue = 0; |
| 98 | size_t hashUpdate = 0; |
| 99 | |
| 100 | std::vector<size_t> hashValueSet; |
| 101 | hashValueSet.push_back(hashValue); |
| 102 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 103 | for (Name::const_iterator it = prefix.begin(); it != prefix.end(); ++it) { |
| 104 | const char* wireFormat = reinterpret_cast<const char*>( it->wire() ); |
| 105 | hashUpdate = CityHash::compute(wireFormat, it->size()); |
| 106 | hashValue ^= hashUpdate; |
| 107 | hashValueSet.push_back(hashValue); |
| 108 | } |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 109 | |
| 110 | return hashValueSet; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 111 | } |
| 112 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 113 | NameTree::NameTree(size_t nBuckets) |
| 114 | : m_nItems(0) |
| 115 | , m_nBuckets(nBuckets) |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 116 | , m_minNBuckets(nBuckets) |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 117 | , m_enlargeLoadFactor(0.5) // more than 50% buckets loaded |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 118 | , m_enlargeFactor(2) // double the hash table size |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 119 | , m_shrinkLoadFactor(0.1) // less than 10% buckets loaded |
| 120 | , m_shrinkFactor(0.5) // reduce the number of buckets by half |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 121 | { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 122 | m_enlargeThreshold = static_cast<size_t>(m_enlargeLoadFactor * static_cast<double>(m_nBuckets)); |
| 123 | m_shrinkThreshold = static_cast<size_t>(m_shrinkLoadFactor * static_cast<double>(m_nBuckets)); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 124 | |
| 125 | // array of node pointers |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 126 | m_buckets = new Node*[m_nBuckets]; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 127 | // Initialize the pointer array |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 128 | for (size_t i = 0; i < m_nBuckets; ++i) { |
| 129 | m_buckets[i] = nullptr; |
| 130 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | NameTree::~NameTree() |
| 134 | { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 135 | for (size_t i = 0; i < m_nBuckets; ++i) { |
| 136 | if (m_buckets[i] != nullptr) { |
| 137 | delete m_buckets[i]; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 138 | } |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 139 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 140 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 141 | delete[] m_buckets; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | // insert() is a private function, and called by only lookup() |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 145 | std::pair<shared_ptr<Entry>, bool> |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 146 | NameTree::insert(const Name& prefix) |
| 147 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 148 | NFD_LOG_TRACE("insert " << prefix); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 149 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 150 | size_t hashValue = computeHash(prefix); |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 151 | size_t loc = hashValue % m_nBuckets; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 152 | |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 153 | NFD_LOG_TRACE("Name " << prefix << " hash value = " << hashValue << " location = " << loc); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 154 | |
| 155 | // Check if this Name has been stored |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 156 | Node* node = m_buckets[loc]; |
| 157 | Node* nodePrev = node; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 158 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 159 | for (node = m_buckets[loc]; node != nullptr; node = node->m_next) { |
| 160 | if (node->m_entry != nullptr) { |
| 161 | if (prefix == node->m_entry->m_prefix) { |
| 162 | return {node->m_entry, false}; // false: old entry |
| 163 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 164 | } |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 165 | nodePrev = node; |
| 166 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 167 | |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 168 | NFD_LOG_TRACE("Did not find " << prefix << ", need to insert it to the table"); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 169 | |
| 170 | // If no bucket is empty occupied, we need to create a new node, and it is |
| 171 | // linked from nodePrev |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 172 | node = new Node(); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 173 | node->m_prev = nodePrev; |
| 174 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 175 | if (nodePrev == nullptr) { |
| 176 | m_buckets[loc] = node; |
| 177 | } |
| 178 | else{ |
| 179 | nodePrev->m_next = node; |
| 180 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 181 | |
| 182 | // Create a new Entry |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 183 | auto entry = make_shared<Entry>(prefix); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 184 | entry->setHash(hashValue); |
| 185 | node->m_entry = entry; // link the Entry to its Node |
| 186 | entry->m_node = node; // link the node to Entry. Used in eraseEntryIfEmpty. |
| 187 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 188 | return {entry, true}; // true: new entry |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Name Prefix Lookup. Create Name Tree Entry if not found |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 192 | shared_ptr<Entry> |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 193 | NameTree::lookup(const Name& prefix) |
| 194 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 195 | NFD_LOG_TRACE("lookup " << prefix); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 196 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 197 | shared_ptr<Entry> entry; |
| 198 | shared_ptr<Entry> parent; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 199 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 200 | for (size_t i = 0; i <= prefix.size(); ++i) { |
| 201 | Name temp = prefix.getPrefix(i); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 202 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 203 | // insert() will create the entry if it does not exist. |
| 204 | bool isNew = false; |
| 205 | std::tie(entry, isNew) = insert(temp); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 206 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 207 | if (isNew) { |
| 208 | ++m_nItems; // Increase the counter |
| 209 | entry->m_parent = parent; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 210 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 211 | if (parent != nullptr) { |
| 212 | parent->m_children.push_back(entry); |
| 213 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 214 | } |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 215 | |
| 216 | if (m_nItems > m_enlargeThreshold) { |
| 217 | resize(m_enlargeFactor * m_nBuckets); |
| 218 | } |
| 219 | |
| 220 | parent = entry; |
| 221 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 222 | return entry; |
| 223 | } |
| 224 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 225 | shared_ptr<Entry> |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 226 | NameTree::lookup(const fib::Entry& fibEntry) const |
| 227 | { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 228 | shared_ptr<Entry> nte = this->getEntry(fibEntry); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 229 | BOOST_ASSERT(nte == nullptr || nte->getFibEntry() == &fibEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 230 | return nte; |
| 231 | } |
| 232 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 233 | shared_ptr<Entry> |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 234 | NameTree::lookup(const pit::Entry& pitEntry) |
| 235 | { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 236 | shared_ptr<Entry> nte = this->getEntry(pitEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 237 | if (nte == nullptr) { |
| 238 | return nullptr; |
| 239 | } |
| 240 | |
| 241 | if (nte->getPrefix().size() == pitEntry.getName().size()) { |
| 242 | return nte; |
| 243 | } |
| 244 | |
| 245 | BOOST_ASSERT(pitEntry.getName().at(-1).isImplicitSha256Digest()); |
| 246 | BOOST_ASSERT(nte->getPrefix() == pitEntry.getName().getPrefix(-1)); |
| 247 | return this->lookup(pitEntry.getName()); |
| 248 | } |
| 249 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 250 | shared_ptr<Entry> |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 251 | NameTree::lookup(const measurements::Entry& measurementsEntry) const |
| 252 | { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 253 | shared_ptr<Entry> nte = this->getEntry(measurementsEntry); |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 254 | BOOST_ASSERT(nte == nullptr || nte->getMeasurementsEntry() == &measurementsEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 255 | return nte; |
| 256 | } |
| 257 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 258 | shared_ptr<Entry> |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 259 | NameTree::lookup(const strategy_choice::Entry& strategyChoiceEntry) const |
| 260 | { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 261 | shared_ptr<Entry> nte = this->getEntry(strategyChoiceEntry); |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 262 | BOOST_ASSERT(nte == nullptr || nte->getStrategyChoiceEntry() == &strategyChoiceEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 263 | return nte; |
| 264 | } |
| 265 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 266 | // return {false: this entry is not empty, true: this entry is empty and erased} |
| 267 | bool |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 268 | NameTree::eraseEntryIfEmpty(shared_ptr<Entry> entry) |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 269 | { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 270 | BOOST_ASSERT(entry != nullptr); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 271 | |
| 272 | NFD_LOG_TRACE("eraseEntryIfEmpty " << entry->getPrefix()); |
| 273 | |
| 274 | // first check if this Entry can be erased |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 275 | if (entry->isEmpty()) { |
| 276 | // update child-related info in the parent |
| 277 | shared_ptr<Entry> parent = entry->getParent(); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 278 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 279 | if (parent != nullptr) { |
| 280 | std::vector<shared_ptr<Entry>>& parentChildrenList = parent->getChildren(); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 281 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 282 | bool isFound = false; |
| 283 | size_t size = parentChildrenList.size(); |
| 284 | for (size_t i = 0; i < size; ++i) { |
| 285 | if (parentChildrenList[i] == entry) { |
| 286 | parentChildrenList[i] = parentChildrenList[size - 1]; |
| 287 | parentChildrenList.pop_back(); |
| 288 | isFound = true; |
| 289 | break; |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 290 | } |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 291 | } |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 292 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 293 | BOOST_VERIFY(isFound == true); |
| 294 | } |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 295 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 296 | // remove this Entry and its Name Tree Node |
| 297 | Node* node = entry->m_node; |
| 298 | Node* nodePrev = node->m_prev; |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 299 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 300 | // configure the previous node |
| 301 | if (nodePrev != nullptr) { |
| 302 | // link the previous node to the next node |
| 303 | nodePrev->m_next = node->m_next; |
| 304 | } |
| 305 | else { |
| 306 | m_buckets[entry->getHash() % m_nBuckets] = node->m_next; |
| 307 | } |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 308 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 309 | // link the previous node with the next node (skip the erased one) |
| 310 | if (node->m_next != nullptr) { |
| 311 | node->m_next->m_prev = nodePrev; |
| 312 | node->m_next = 0; |
| 313 | } |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 314 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 315 | BOOST_ASSERT(node->m_next == nullptr); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 316 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 317 | --m_nItems; |
| 318 | delete node; |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 319 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 320 | if (parent != nullptr) { |
| 321 | eraseEntryIfEmpty(parent); |
| 322 | } |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 323 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 324 | size_t newNBuckets = static_cast<size_t>(m_shrinkFactor * static_cast<double>(m_nBuckets)); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 325 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 326 | if (newNBuckets >= m_minNBuckets && m_nItems < m_shrinkThreshold) { |
| 327 | resize(newNBuckets); |
| 328 | } |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 329 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 330 | return true; |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 331 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | return false; |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 335 | } |
| 336 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 337 | // Exact Match |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 338 | shared_ptr<Entry> |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 339 | NameTree::findExactMatch(const Name& prefix) const |
| 340 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 341 | NFD_LOG_TRACE("findExactMatch " << prefix); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 342 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 343 | size_t hashValue = computeHash(prefix); |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 344 | size_t loc = hashValue % m_nBuckets; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 345 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 346 | NFD_LOG_TRACE("Name " << prefix << " hash value = " << hashValue << " location = " << loc); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 347 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 348 | shared_ptr<Entry> entry; |
| 349 | Node* node = nullptr; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 350 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 351 | for (node = m_buckets[loc]; node != nullptr; node = node->m_next) { |
| 352 | entry = node->m_entry; |
| 353 | if (entry != nullptr) { |
| 354 | if (hashValue == entry->getHash() && prefix == entry->getPrefix()) { |
| 355 | return entry; |
| 356 | } |
| 357 | } |
| 358 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 359 | |
| 360 | // if not found, the default value of entry (null pointer) will be returned |
| 361 | entry.reset(); |
| 362 | return entry; |
| 363 | } |
| 364 | |
| 365 | // Longest Prefix Match |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 366 | shared_ptr<Entry> |
| 367 | NameTree::findLongestPrefixMatch(const Name& prefix, const EntrySelector& entrySelector) const |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 368 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 369 | NFD_LOG_TRACE("findLongestPrefixMatch " << prefix); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 370 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 371 | shared_ptr<Entry> entry; |
| 372 | std::vector<size_t> hashValueSet = computeHashSet(prefix); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 373 | |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 374 | size_t hashValue = 0; |
| 375 | size_t loc = 0; |
| 376 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 377 | for (int i = static_cast<int>(prefix.size()); i >= 0; --i) { |
| 378 | hashValue = hashValueSet[i]; |
| 379 | loc = hashValue % m_nBuckets; |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 380 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 381 | Node* node = nullptr; |
| 382 | for (node = m_buckets[loc]; node != nullptr; node = node->m_next) { |
| 383 | entry = node->m_entry; |
| 384 | if (entry != nullptr) { |
| 385 | // isPrefixOf() is used to avoid making a copy of the name |
| 386 | if (hashValue == entry->getHash() && |
| 387 | entry->getPrefix().isPrefixOf(prefix) && |
| 388 | entrySelector(*entry)) { |
| 389 | return entry; |
| 390 | } |
| 391 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 392 | } |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 393 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 394 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 395 | return nullptr; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 396 | } |
| 397 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 398 | shared_ptr<Entry> |
| 399 | NameTree::findLongestPrefixMatch(shared_ptr<Entry> entry, |
| 400 | const EntrySelector& entrySelector) const |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 401 | { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 402 | while (entry != nullptr) { |
| 403 | if (entrySelector(*entry)) { |
| 404 | return entry; |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 405 | } |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 406 | entry = entry->getParent(); |
| 407 | } |
| 408 | return nullptr; |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 409 | } |
| 410 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 411 | shared_ptr<Entry> |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 412 | NameTree::findLongestPrefixMatch(const pit::Entry& pitEntry) const |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 413 | { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 414 | shared_ptr<Entry> nte = this->getEntry(pitEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 415 | BOOST_ASSERT(nte != nullptr); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 416 | if (nte->getPrefix().size() == pitEntry.getName().size()) { |
| 417 | return nte; |
| 418 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 419 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 420 | BOOST_ASSERT(pitEntry.getName().at(-1).isImplicitSha256Digest()); |
| 421 | BOOST_ASSERT(nte->getPrefix() == pitEntry.getName().getPrefix(-1)); |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 422 | shared_ptr<Entry> exact = this->findExactMatch(pitEntry.getName()); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 423 | return exact == nullptr ? nte : exact; |
| 424 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 425 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 426 | boost::iterator_range<NameTree::const_iterator> |
| 427 | NameTree::findAllMatches(const Name& prefix, |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 428 | const EntrySelector& entrySelector) const |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 429 | { |
| 430 | NFD_LOG_TRACE("NameTree::findAllMatches" << prefix); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 431 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 432 | // As we are using Name Prefix Hash Table, and the current LPM() is |
| 433 | // implemented as starting from full name, and reduce the number of |
| 434 | // components by 1 each time, we could use it here. |
| 435 | // For trie-like design, it could be more efficient by walking down the |
| 436 | // trie from the root node. |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 437 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 438 | shared_ptr<Entry> entry = findLongestPrefixMatch(prefix, entrySelector); |
Junxiao Shi | 029401f | 2016-08-05 12:55:14 +0000 | [diff] [blame^] | 439 | return {Iterator(make_shared<PrefixMatchImpl>(*this, entrySelector), entry), end()}; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 440 | } |
| 441 | |
Junxiao Shi | 5ccd0c2 | 2014-12-02 23:54:42 -0700 | [diff] [blame] | 442 | boost::iterator_range<NameTree::const_iterator> |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 443 | NameTree::fullEnumerate(const EntrySelector& entrySelector) const |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 444 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 445 | NFD_LOG_TRACE("fullEnumerate"); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 446 | |
Junxiao Shi | 029401f | 2016-08-05 12:55:14 +0000 | [diff] [blame^] | 447 | return {Iterator(make_shared<FullEnumerationImpl>(*this, entrySelector), nullptr), end()}; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 448 | } |
| 449 | |
Junxiao Shi | 5ccd0c2 | 2014-12-02 23:54:42 -0700 | [diff] [blame] | 450 | boost::iterator_range<NameTree::const_iterator> |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 451 | NameTree::partialEnumerate(const Name& prefix, |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 452 | const EntrySubTreeSelector& entrySubTreeSelector) const |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 453 | { |
| 454 | // the first step is to process the root node |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 455 | shared_ptr<Entry> entry = findExactMatch(prefix); |
Junxiao Shi | 029401f | 2016-08-05 12:55:14 +0000 | [diff] [blame^] | 456 | return {Iterator(make_shared<PartialEnumerationImpl>(*this, entrySubTreeSelector), entry), end()}; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 457 | } |
| 458 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 459 | // Hash Table Resize |
| 460 | void |
| 461 | NameTree::resize(size_t newNBuckets) |
| 462 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 463 | NFD_LOG_TRACE("resize"); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 464 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 465 | Node** newBuckets = new Node*[newNBuckets]; |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 466 | size_t count = 0; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 467 | |
| 468 | // referenced ccnx hashtb.c hashtb_rehash() |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 469 | Node** pp = nullptr; |
| 470 | Node* p = nullptr; |
| 471 | Node* pre = nullptr; |
| 472 | Node* q = nullptr; // record p->m_next |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 473 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 474 | for (size_t i = 0; i < newNBuckets; ++i) { |
| 475 | newBuckets[i] = nullptr; |
| 476 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 477 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 478 | for (size_t i = 0; i < m_nBuckets; ++i) { |
| 479 | for (p = m_buckets[i]; p != nullptr; p = q) { |
| 480 | ++count; |
| 481 | q = p->m_next; |
| 482 | BOOST_ASSERT(p->m_entry != nullptr); |
| 483 | uint32_t h = p->m_entry->m_hash; |
| 484 | uint32_t b = h % newNBuckets; |
| 485 | pre = nullptr; |
| 486 | for (pp = &newBuckets[b]; *pp != nullptr; pp = &((*pp)->m_next)) { |
| 487 | pre = *pp; |
| 488 | } |
| 489 | p->m_prev = pre; |
| 490 | p->m_next = *pp; // Actually *pp always == nullptr in this case |
| 491 | *pp = p; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 492 | } |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 493 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 494 | |
| 495 | BOOST_ASSERT(count == m_nItems); |
| 496 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 497 | Node** oldBuckets = m_buckets; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 498 | m_buckets = newBuckets; |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 499 | delete[] oldBuckets; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 500 | |
| 501 | m_nBuckets = newNBuckets; |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 502 | m_enlargeThreshold = static_cast<size_t>(m_enlargeLoadFactor * static_cast<double>(m_nBuckets)); |
| 503 | m_shrinkThreshold = static_cast<size_t>(m_shrinkLoadFactor * static_cast<double>(m_nBuckets)); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | // For debugging |
| 507 | void |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 508 | NameTree::dump(std::ostream& output) const |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 509 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 510 | NFD_LOG_TRACE("dump()"); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 511 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 512 | Node* node = nullptr; |
| 513 | shared_ptr<Entry> entry; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 514 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 515 | for (size_t i = 0; i < m_nBuckets; ++i) { |
| 516 | for (node = m_buckets[i]; node != nullptr; node = node->m_next) { |
| 517 | entry = node->m_entry; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 518 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 519 | // if the Entry exist, dump its information |
| 520 | if (entry != nullptr) { |
| 521 | output << "Bucket" << i << '\t' << entry->m_prefix.toUri() << '\n'; |
| 522 | output << "\t\tHash " << entry->m_hash << '\n'; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 523 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 524 | if (entry->m_parent != nullptr) { |
| 525 | output << "\t\tparent->" << entry->m_parent->m_prefix.toUri(); |
| 526 | } |
| 527 | else { |
| 528 | output << "\t\tROOT"; |
| 529 | } |
| 530 | output << '\n'; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 531 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 532 | if (!entry->m_children.empty()) { |
| 533 | output << "\t\tchildren = " << entry->m_children.size() << '\n'; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 534 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 535 | for (size_t j = 0; j < entry->m_children.size(); ++j) { |
| 536 | output << "\t\t\tChild " << j << " " << entry->m_children[j]->getPrefix() << '\n'; |
| 537 | } |
| 538 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 539 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 540 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 541 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 542 | } |
| 543 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 544 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 545 | output << "Bucket count = " << m_nBuckets << '\n'; |
| 546 | output << "Stored item = " << m_nItems << '\n'; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 547 | output << "--------------------------\n"; |
| 548 | } |
| 549 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 550 | } // namespace name_tree |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 551 | } // namespace nfd |