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 | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 24 | */ |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_TABLE_NAME_TREE_HPP |
| 27 | #define NFD_DAEMON_TABLE_NAME_TREE_HPP |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 28 | |
| 29 | #include "common.hpp" |
| 30 | #include "name-tree-entry.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace name_tree { |
| 34 | |
| 35 | /** |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 36 | * \brief Compute the hash value of the given name prefix's WIRE FORMAT |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 37 | */ |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 38 | size_t |
| 39 | computeHash(const Name& prefix); |
| 40 | |
| 41 | /** |
| 42 | * \brief Incrementally compute hash values |
| 43 | * \return Return a vector of hash values, starting from the root prefix |
| 44 | */ |
| 45 | std::vector<size_t> |
| 46 | computeHashSet(const Name& prefix); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 47 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 48 | /// a predicate to accept or reject an Entry in find operations |
| 49 | typedef function<bool (const Entry& entry)> EntrySelector; |
| 50 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 51 | /** |
| 52 | * \brief a predicate to accept or reject an Entry and its children |
| 53 | * \return .first indicates whether entry should be accepted; |
| 54 | * .second indicates whether entry's children should be visited |
| 55 | */ |
| 56 | typedef function<std::pair<bool,bool> (const Entry& entry)> EntrySubTreeSelector; |
| 57 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 58 | struct AnyEntry { |
| 59 | bool |
| 60 | operator()(const Entry& entry) |
| 61 | { |
| 62 | return true; |
| 63 | } |
| 64 | }; |
| 65 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 66 | struct AnyEntrySubTree { |
| 67 | std::pair<bool, bool> |
| 68 | operator()(const Entry& entry) |
| 69 | { |
| 70 | return std::make_pair(true, true); |
| 71 | } |
| 72 | }; |
| 73 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 74 | } // namespace name_tree |
| 75 | |
| 76 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 77 | * \brief Class Name Tree |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 78 | */ |
| 79 | class NameTree : noncopyable |
| 80 | { |
| 81 | public: |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 82 | class const_iterator; |
| 83 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 84 | explicit |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 85 | NameTree(size_t nBuckets = 1024); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 86 | |
| 87 | ~NameTree(); |
| 88 | |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 89 | public: // information |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 90 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 91 | * \brief Get the number of occupied entries in the Name Tree |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 92 | */ |
| 93 | size_t |
| 94 | size() const; |
| 95 | |
| 96 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 97 | * \brief Get the number of buckets in the Name Tree (NPHT) |
| 98 | * \details The number of buckets is the one that used to create the hash |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 99 | * table, i.e., m_nBuckets. |
| 100 | */ |
| 101 | size_t |
| 102 | getNBuckets() const; |
| 103 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame^] | 104 | /** \return Name Tree Entry on which a table entry is attached |
| 105 | */ |
| 106 | template<typename ENTRY> |
| 107 | shared_ptr<name_tree::Entry> |
| 108 | getEntry(const ENTRY& tableEntry) const; |
| 109 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 110 | /** |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 111 | * \brief Dump all the information stored in the Name Tree for debugging. |
| 112 | */ |
| 113 | void |
| 114 | dump(std::ostream& output) const; |
| 115 | |
| 116 | public: // mutation |
| 117 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 118 | * \brief Look for the Name Tree Entry that contains this name prefix. |
| 119 | * \details Starts from the shortest name prefix, and then increase the |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 120 | * number of name components by one each time. All non-existing Name Tree |
| 121 | * Entries will be created. |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 122 | * \param prefix The querying name prefix. |
| 123 | * \return The pointer to the Name Tree Entry that contains this full name |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 124 | * prefix. |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 125 | * \note Existing iterators are unaffected. |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 126 | */ |
| 127 | shared_ptr<name_tree::Entry> |
| 128 | lookup(const Name& prefix); |
| 129 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame^] | 130 | /** \brief get NameTree entry from FIB entry |
| 131 | * |
| 132 | * This is equivalent to .lookup(fibEntry.getPrefix()) |
| 133 | */ |
| 134 | shared_ptr<name_tree::Entry> |
| 135 | lookup(const fib::Entry& fibEntry) const; |
| 136 | |
| 137 | /** \brief get NameTree entry from PIT entry |
| 138 | * |
| 139 | * This is equivalent to .lookup(pitEntry.getName()). |
| 140 | */ |
| 141 | shared_ptr<name_tree::Entry> |
| 142 | lookup(const pit::Entry& pitEntry); |
| 143 | |
| 144 | /** \brief get NameTree entry from Measurements entry |
| 145 | * |
| 146 | * This is equivalent to .lookup(measurementsEntry.getName()) |
| 147 | */ |
| 148 | shared_ptr<name_tree::Entry> |
| 149 | lookup(const measurements::Entry& measurementsEntry) const; |
| 150 | |
| 151 | /** \brief get NameTree entry from StrategyChoice entry |
| 152 | * |
| 153 | * This is equivalent to .lookup(strategyChoiceEntry.getName()) |
| 154 | */ |
| 155 | shared_ptr<name_tree::Entry> |
| 156 | lookup(const strategy_choice::Entry& strategyChoiceEntry) const; |
| 157 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 158 | /** |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 159 | * \brief Delete a Name Tree Entry if this entry is empty. |
| 160 | * \param entry The entry to be deleted if empty. |
| 161 | * \note This function must be called after a table entry is detached from Name Tree |
| 162 | * entry. The function deletes a Name Tree entry if nothing is attached to it and |
| 163 | * it has no children, then repeats the same process on its ancestors. |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 164 | * \note Existing iterators, except those pointing to deleted entries, are unaffected. |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 165 | */ |
| 166 | bool |
| 167 | eraseEntryIfEmpty(shared_ptr<name_tree::Entry> entry); |
| 168 | |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 169 | public: // matching |
| 170 | /** |
| 171 | * \brief Exact match lookup for the given name prefix. |
| 172 | * \return a null shared_ptr if this prefix is not found; |
| 173 | * otherwise return the Name Tree Entry address |
| 174 | */ |
| 175 | shared_ptr<name_tree::Entry> |
| 176 | findExactMatch(const Name& prefix) const; |
| 177 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 178 | /** |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 179 | * \brief Longest prefix matching for the given name |
| 180 | * \details Starts from the full name string, reduce the number of name component |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 181 | * by one each time, until an Entry is found. |
| 182 | */ |
| 183 | shared_ptr<name_tree::Entry> |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 184 | findLongestPrefixMatch(const Name& prefix, |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 185 | const name_tree::EntrySelector& entrySelector = |
| 186 | name_tree::AnyEntry()) const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 187 | |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 188 | shared_ptr<name_tree::Entry> |
| 189 | findLongestPrefixMatch(shared_ptr<name_tree::Entry> entry, |
| 190 | const name_tree::EntrySelector& entrySelector = |
| 191 | name_tree::AnyEntry()) const; |
| 192 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 193 | /** \brief longest prefix matching for Interest name of the PIT entry |
| 194 | * |
| 195 | * This is equivalent to .findLongestPrefixMatch(pitEntry.getName(), AnyEntry()). |
| 196 | */ |
| 197 | shared_ptr<name_tree::Entry> |
| 198 | findLongestPrefixMatch(const pit::Entry& pitEntry) const; |
| 199 | |
Junxiao Shi | 2b73ca3 | 2014-11-17 19:16:08 -0700 | [diff] [blame] | 200 | /** \brief Enumerate all the name prefixes that satisfy the prefix and entrySelector |
| 201 | * \return an unspecified type that have .begin() and .end() methods |
| 202 | * and is usable with range-based for |
| 203 | * |
| 204 | * Example: |
| 205 | * \code{.cpp} |
| 206 | * auto&& allMatches = nt.findAllMatches(Name("/A/B/C")); |
| 207 | * for (const name_tree::Entry& nte : allMatches) { |
| 208 | * ... |
| 209 | * } |
| 210 | * \endcode |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 211 | * \note Iteration order is implementation-specific and is undefined |
| 212 | * \note The returned iterator may get invalidated when NameTree is modified |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 213 | */ |
Junxiao Shi | 5ccd0c2 | 2014-12-02 23:54:42 -0700 | [diff] [blame] | 214 | boost::iterator_range<const_iterator> |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 215 | findAllMatches(const Name& prefix, |
| 216 | const name_tree::EntrySelector& entrySelector = name_tree::AnyEntry()) const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 217 | |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 218 | public: // enumeration |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 219 | /** \brief Enumerate all entries, optionally filtered by an EntrySelector. |
| 220 | * \return an unspecified type that have .begin() and .end() methods |
| 221 | * and is usable with range-based for |
| 222 | * |
| 223 | * Example: |
| 224 | * \code{.cpp} |
| 225 | * auto&& enumerable = nt.fullEnumerate(); |
| 226 | * for (const name_tree::Entry& nte : enumerable) { |
| 227 | * ... |
| 228 | * } |
| 229 | * \endcode |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 230 | * \note Iteration order is implementation-specific and is undefined |
| 231 | * \note The returned iterator may get invalidated when NameTree is modified |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 232 | */ |
Junxiao Shi | 5ccd0c2 | 2014-12-02 23:54:42 -0700 | [diff] [blame] | 233 | boost::iterator_range<const_iterator> |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 234 | fullEnumerate(const name_tree::EntrySelector& entrySelector = name_tree::AnyEntry()) const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 235 | |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 236 | /** \brief Enumerate all entries under a prefix, optionally filtered by an EntrySubTreeSelector. |
| 237 | * \return an unspecified type that have .begin() and .end() methods |
| 238 | * and is usable with range-based for |
| 239 | * |
| 240 | * Example: |
| 241 | * \code{.cpp} |
| 242 | * auto&& enumerable = nt.partialEnumerate(Name("/A/B/C")); |
| 243 | * for (const name_tree::Entry& nte : enumerable) { |
| 244 | * ... |
| 245 | * } |
| 246 | * \endcode |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 247 | * \note Iteration order is implementation-specific and is undefined |
| 248 | * \note The returned iterator may get invalidated when NameTree is modified |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 249 | */ |
Junxiao Shi | 5ccd0c2 | 2014-12-02 23:54:42 -0700 | [diff] [blame] | 250 | boost::iterator_range<const_iterator> |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 251 | partialEnumerate(const Name& prefix, |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 252 | const name_tree::EntrySubTreeSelector& entrySubTreeSelector = |
| 253 | name_tree::AnyEntrySubTree()) const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 254 | |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 255 | /** \brief Get an iterator pointing to the first NameTree entry |
| 256 | * \note Iteration order is implementation-specific and is undefined |
| 257 | * \note The returned iterator may get invalidated when NameTree is modified |
| 258 | */ |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 259 | const_iterator |
| 260 | begin() const; |
| 261 | |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 262 | /** \brief Get an iterator referring to the past-the-end FIB entry |
| 263 | * \note Iteration order is implementation-specific and is undefined |
| 264 | * \note The returned iterator may get invalidated when NameTree is modified |
| 265 | */ |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 266 | const_iterator |
| 267 | end() const; |
| 268 | |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 269 | enum IteratorType { |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 270 | FULL_ENUMERATE_TYPE, |
| 271 | PARTIAL_ENUMERATE_TYPE, |
| 272 | FIND_ALL_MATCHES_TYPE |
| 273 | }; |
| 274 | |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 275 | class const_iterator : public std::iterator<std::forward_iterator_tag, const name_tree::Entry> |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 276 | { |
| 277 | public: |
| 278 | friend class NameTree; |
| 279 | |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 280 | const_iterator(); |
| 281 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 282 | const_iterator(NameTree::IteratorType type, |
| 283 | const NameTree& nameTree, |
| 284 | shared_ptr<name_tree::Entry> entry, |
| 285 | const name_tree::EntrySelector& entrySelector = name_tree::AnyEntry(), |
| 286 | const name_tree::EntrySubTreeSelector& entrySubTreeSelector = name_tree::AnyEntrySubTree()); |
| 287 | |
| 288 | ~const_iterator(); |
| 289 | |
| 290 | const name_tree::Entry& |
| 291 | operator*() const; |
| 292 | |
| 293 | shared_ptr<name_tree::Entry> |
| 294 | operator->() const; |
| 295 | |
| 296 | const_iterator |
| 297 | operator++(); |
| 298 | |
| 299 | const_iterator |
| 300 | operator++(int); |
| 301 | |
| 302 | bool |
| 303 | operator==(const const_iterator& other) const; |
| 304 | |
| 305 | bool |
| 306 | operator!=(const const_iterator& other) const; |
| 307 | |
| 308 | private: |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 309 | const NameTree* m_nameTree; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 310 | shared_ptr<name_tree::Entry> m_entry; |
| 311 | shared_ptr<name_tree::Entry> m_subTreeRoot; |
| 312 | shared_ptr<name_tree::EntrySelector> m_entrySelector; |
| 313 | shared_ptr<name_tree::EntrySubTreeSelector> m_entrySubTreeSelector; |
| 314 | NameTree::IteratorType m_type; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 315 | bool m_shouldVisitChildren; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 316 | }; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 317 | |
| 318 | private: |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 319 | /** |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame^] | 320 | * \brief Create a Name Tree Entry if it does not exist, or return the existing |
| 321 | * Name Tree Entry address. |
| 322 | * \details Called by lookup() only. |
| 323 | * \return The first item is the Name Tree Entry address, the second item is |
| 324 | * a bool value indicates whether this is an old entry (false) or a new |
| 325 | * entry (true). |
| 326 | */ |
| 327 | std::pair<shared_ptr<name_tree::Entry>, bool> |
| 328 | insert(const Name& prefix); |
| 329 | |
| 330 | /** |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 331 | * \brief Resize the hash table size when its load factor reaches a threshold. |
| 332 | * \details As we are currently using a hand-written hash table implementation |
| 333 | * for the Name Tree, the hash table resize() function should be kept in the |
| 334 | * name-tree.hpp file. |
| 335 | * \param newNBuckets The number of buckets for the new hash table. |
| 336 | */ |
| 337 | void |
| 338 | resize(size_t newNBuckets); |
| 339 | |
| 340 | private: |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 341 | size_t m_nItems; // Number of items being stored |
| 342 | size_t m_nBuckets; // Number of hash buckets |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 343 | size_t m_minNBuckets; // Minimum number of hash buckets |
| 344 | double m_enlargeLoadFactor; |
| 345 | size_t m_enlargeThreshold; |
| 346 | int m_enlargeFactor; |
| 347 | double m_shrinkLoadFactor; |
| 348 | size_t m_shrinkThreshold; |
| 349 | double m_shrinkFactor; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 350 | name_tree::Node** m_buckets; // Name Tree Buckets in the NPHT |
| 351 | shared_ptr<name_tree::Entry> m_end; |
| 352 | const_iterator m_endIterator; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 353 | }; |
| 354 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 355 | inline NameTree::const_iterator::~const_iterator() |
| 356 | { |
| 357 | } |
| 358 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 359 | inline size_t |
| 360 | NameTree::size() const |
| 361 | { |
| 362 | return m_nItems; |
| 363 | } |
| 364 | |
| 365 | inline size_t |
| 366 | NameTree::getNBuckets() const |
| 367 | { |
| 368 | return m_nBuckets; |
| 369 | } |
| 370 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame^] | 371 | template<typename ENTRY> |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 372 | inline shared_ptr<name_tree::Entry> |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame^] | 373 | NameTree::getEntry(const ENTRY& tableEntry) const |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 374 | { |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame^] | 375 | return tableEntry.m_nameTreeEntry.lock(); |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 376 | } |
| 377 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 378 | inline NameTree::const_iterator |
| 379 | NameTree::begin() const |
| 380 | { |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 381 | return fullEnumerate().begin(); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | inline NameTree::const_iterator |
| 385 | NameTree::end() const |
| 386 | { |
| 387 | return m_endIterator; |
| 388 | } |
| 389 | |
| 390 | inline const name_tree::Entry& |
| 391 | NameTree::const_iterator::operator*() const |
| 392 | { |
| 393 | return *m_entry; |
| 394 | } |
| 395 | |
| 396 | inline shared_ptr<name_tree::Entry> |
| 397 | NameTree::const_iterator::operator->() const |
| 398 | { |
| 399 | return m_entry; |
| 400 | } |
| 401 | |
| 402 | inline NameTree::const_iterator |
| 403 | NameTree::const_iterator::operator++(int) |
| 404 | { |
| 405 | NameTree::const_iterator temp(*this); |
| 406 | ++(*this); |
| 407 | return temp; |
| 408 | } |
| 409 | |
| 410 | inline bool |
| 411 | NameTree::const_iterator::operator==(const NameTree::const_iterator& other) const |
| 412 | { |
| 413 | return m_entry == other.m_entry; |
| 414 | } |
| 415 | |
| 416 | inline bool |
| 417 | NameTree::const_iterator::operator!=(const NameTree::const_iterator& other) const |
| 418 | { |
| 419 | return m_entry != other.m_entry; |
| 420 | } |
| 421 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 422 | } // namespace nfd |
| 423 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 424 | #endif // NFD_DAEMON_TABLE_NAME_TREE_HPP |