HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | c0a5a39 | 2017-08-19 16:49:30 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, 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 | |
Junxiao Shi | 029401f | 2016-08-05 12:55:14 +0000 | [diff] [blame] | 29 | #include "name-tree-iterator.hpp" |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | namespace name_tree { |
| 33 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 34 | /** \brief a common index structure for FIB, PIT, StrategyChoice, and Measurements |
| 35 | */ |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 36 | class NameTree : noncopyable |
| 37 | { |
| 38 | public: |
| 39 | explicit |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 40 | NameTree(size_t nBuckets = 1024); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 41 | |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 42 | public: // information |
Junxiao Shi | f54d030 | 2017-09-07 18:16:38 +0000 | [diff] [blame] | 43 | /** \brief Maximum depth of the name tree. |
| 44 | * |
| 45 | * Calling NameTree::lookup with a name with many components would cause the creation of many |
| 46 | * NameTree entries, which could take very long time. This constant limits the maximum number of |
| 47 | * name components in the name of a NameTree entry. Thus, it limits the number of NameTree |
| 48 | * entries created from a long name, bounding the processing complexity. |
| 49 | * |
| 50 | * This constant is currently advisory. It is enforced in NameTree::lookup only if |
| 51 | * \p enforceMaxDepth is set to true. This will become mandatory later. |
| 52 | */ |
| 53 | static size_t |
| 54 | getMaxDepth() |
| 55 | { |
| 56 | return 32; |
| 57 | } |
| 58 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 59 | /** \return number of name tree entries |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 60 | */ |
| 61 | size_t |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame] | 62 | size() const |
| 63 | { |
| 64 | return m_ht.size(); |
| 65 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 66 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 67 | /** \return number of hashtable buckets |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 68 | */ |
| 69 | size_t |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame] | 70 | getNBuckets() const |
| 71 | { |
| 72 | return m_ht.getNBuckets(); |
| 73 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 74 | |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 75 | /** \return name tree entry on which a table entry is attached, |
| 76 | * or nullptr if the table entry is detached |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 77 | */ |
Davide Pesavento | c0a5a39 | 2017-08-19 16:49:30 -0400 | [diff] [blame] | 78 | template<typename EntryT> |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 79 | Entry* |
Davide Pesavento | c0a5a39 | 2017-08-19 16:49:30 -0400 | [diff] [blame] | 80 | getEntry(const EntryT& tableEntry) const |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame] | 81 | { |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 82 | return Entry::get(tableEntry); |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame] | 83 | } |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 84 | |
| 85 | public: // mutation |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 86 | /** \brief find or insert an entry with specified name |
| 87 | * \param name a name prefix |
Junxiao Shi | f54d030 | 2017-09-07 18:16:38 +0000 | [diff] [blame] | 88 | * \param enforceMaxDepth if true, use \p name.getPrefix(getMaxDepth()) in place of \p name |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 89 | * \return an entry with \p name |
| 90 | * \post an entry with \p name and all ancestors are created |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 91 | * \note Existing iterators are unaffected. |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 92 | */ |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 93 | Entry& |
Junxiao Shi | f54d030 | 2017-09-07 18:16:38 +0000 | [diff] [blame] | 94 | lookup(const Name& name, bool enforceMaxDepth = false); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 95 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 96 | /** \brief equivalent to .lookup(fibEntry.getPrefix()) |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 97 | * \param fibEntry a FIB entry attached to this name tree, or Fib::s_emptyEntry |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 98 | * \note This overload is more efficient than .lookup(const Name&) in common cases. |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 99 | */ |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 100 | Entry& |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 101 | lookup(const fib::Entry& fibEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 102 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 103 | /** \brief equivalent to .lookup(pitEntry.getName()). |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 104 | * \param pitEntry a PIT entry attached to this name tree |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 105 | * \note This overload is more efficient than .lookup(const Name&) in common cases. |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 106 | */ |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 107 | Entry& |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 108 | lookup(const pit::Entry& pitEntry); |
| 109 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 110 | /** \brief equivalent to .lookup(measurementsEntry.getName()) |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 111 | * \param measurementsEntry a Measurements entry attached to this name tree |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 112 | * \note This overload is more efficient than .lookup(const Name&) in common cases. |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 113 | */ |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 114 | Entry& |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 115 | lookup(const measurements::Entry& measurementsEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 116 | |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 117 | /** \brief equivalent to .lookup(strategyChoiceEntry.getPrefix()) |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 118 | * \param strategyChoiceEntry a StrategyChoice entry attached to this name tree |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 119 | * \note This overload is more efficient than .lookup(const Name&) in common cases. |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 120 | */ |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 121 | Entry& |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 122 | lookup(const strategy_choice::Entry& strategyChoiceEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 123 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 124 | /** \brief delete the entry if it is empty |
| 125 | * \param entry a valid entry |
Junxiao Shi | e7258ff | 2016-08-12 23:55:47 +0000 | [diff] [blame] | 126 | * \param canEraseAncestors whether ancestors should be deleted if they become empty |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 127 | * \return number of deleted entries |
| 128 | * \sa Entry::isEmpty() |
Junxiao Shi | e7258ff | 2016-08-12 23:55:47 +0000 | [diff] [blame] | 129 | * \post If the entry is empty, it's deleted. If canEraseAncestors is true, |
| 130 | * ancestors of the entry are also deleted if they become empty. |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 131 | * \note This function must be called after detaching a table entry from a name tree entry, |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 132 | * \note Existing iterators, except those pointing to deleted entries, are unaffected. |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 133 | */ |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame] | 134 | size_t |
Junxiao Shi | e7258ff | 2016-08-12 23:55:47 +0000 | [diff] [blame] | 135 | eraseIfEmpty(Entry* entry, bool canEraseAncestors = true); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 136 | |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 137 | public: // matching |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 138 | /** \brief exact match lookup |
Junxiao Shi | 042a331 | 2017-09-15 02:51:20 +0000 | [diff] [blame^] | 139 | * \return entry with \p name.getPrefix(prefixLen), or nullptr if it does not exist |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 140 | */ |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 141 | Entry* |
Junxiao Shi | 042a331 | 2017-09-15 02:51:20 +0000 | [diff] [blame^] | 142 | findExactMatch(const Name& name, size_t prefixLen = std::numeric_limits<size_t>::max()) const; |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 143 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 144 | /** \brief longest prefix matching |
| 145 | * \return entry whose name is a prefix of \p name and passes \p entrySelector, |
| 146 | * where no other entry with a longer name satisfies those requirements; |
| 147 | * or nullptr if no entry satisfying those requirements exists |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 148 | */ |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 149 | Entry* |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame] | 150 | findLongestPrefixMatch(const Name& name, |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 151 | const EntrySelector& entrySelector = AnyEntry()) const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 152 | |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 153 | /** \brief equivalent to .findLongestPrefixMatch(entry.getName(), entrySelector) |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 154 | * \note This overload is more efficient than |
| 155 | * .findLongestPrefixMatch(const Name&, const EntrySelector&) in common cases. |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 156 | */ |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 157 | Entry* |
| 158 | findLongestPrefixMatch(const Entry& entry, |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 159 | const EntrySelector& entrySelector = AnyEntry()) const; |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 160 | |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 161 | /** \brief equivalent to .findLongestPrefixMatch(getEntry(tableEntry)->getName(), entrySelector) |
Davide Pesavento | c0a5a39 | 2017-08-19 16:49:30 -0400 | [diff] [blame] | 162 | * \tparam EntryT fib::Entry or measurements::Entry or strategy_choice::Entry |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 163 | * \note This overload is more efficient than |
| 164 | * .findLongestPrefixMatch(const Name&, const EntrySelector&) in common cases. |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 165 | * \warning Undefined behavior may occur if tableEntry is not attached to this name tree. |
| 166 | */ |
Davide Pesavento | c0a5a39 | 2017-08-19 16:49:30 -0400 | [diff] [blame] | 167 | template<typename EntryT> |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 168 | Entry* |
Davide Pesavento | c0a5a39 | 2017-08-19 16:49:30 -0400 | [diff] [blame] | 169 | findLongestPrefixMatch(const EntryT& tableEntry, |
| 170 | const EntrySelector& entrySelector = AnyEntry()) const |
| 171 | { |
| 172 | const Entry* nte = this->getEntry(tableEntry); |
| 173 | BOOST_ASSERT(nte != nullptr); |
| 174 | return this->findLongestPrefixMatch(*nte, entrySelector); |
| 175 | } |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 176 | |
| 177 | /** \brief equivalent to .findLongestPrefixMatch(pitEntry.getName(), entrySelector) |
| 178 | * \note This overload is more efficient than |
| 179 | * .findLongestPrefixMatch(const Name&, const EntrySelector&) in common cases. |
| 180 | * \warning Undefined behavior may occur if pitEntry is not attached to this name tree. |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 181 | */ |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 182 | Entry* |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 183 | findLongestPrefixMatch(const pit::Entry& pitEntry, |
| 184 | const EntrySelector& entrySelector = AnyEntry()) const; |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 185 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 186 | /** \brief all-prefixes match lookup |
Junxiao Shi | 9f6ca60 | 2016-08-15 04:50:29 +0000 | [diff] [blame] | 187 | * \return a range where every entry has a name that is a prefix of \p name , |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 188 | * and matches \p entrySelector. |
Junxiao Shi | 2b73ca3 | 2014-11-17 19:16:08 -0700 | [diff] [blame] | 189 | * |
| 190 | * Example: |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 191 | * \code |
| 192 | * Name name("/A/B/C"); |
| 193 | * auto&& allMatches = nt.findAllMatches(name); |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 194 | * for (const Entry& nte : allMatches) { |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 195 | * BOOST_ASSERT(nte.getName().isPrefixOf(name)); |
Junxiao Shi | 2b73ca3 | 2014-11-17 19:16:08 -0700 | [diff] [blame] | 196 | * ... |
| 197 | * } |
| 198 | * \endcode |
Junxiao Shi | b30863e | 2016-08-15 21:32:01 +0000 | [diff] [blame] | 199 | * \note Iteration order is implementation-defined. |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 200 | * \warning If a name tree entry whose name is a prefix of \p name is inserted |
| 201 | * during the enumeration, it may or may not be visited. |
| 202 | * If a name tree entry whose name is a prefix of \p name is deleted |
| 203 | * during the enumeration, undefined behavior may occur. |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 204 | */ |
Junxiao Shi | 9f6ca60 | 2016-08-15 04:50:29 +0000 | [diff] [blame] | 205 | Range |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 206 | findAllMatches(const Name& name, |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 207 | const EntrySelector& entrySelector = AnyEntry()) const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 208 | |
Alexander Afanasyev | b303324 | 2014-08-04 11:09:05 -0700 | [diff] [blame] | 209 | public: // enumeration |
Junxiao Shi | f54d030 | 2017-09-07 18:16:38 +0000 | [diff] [blame] | 210 | using const_iterator = Iterator; |
Junxiao Shi | 9f6ca60 | 2016-08-15 04:50:29 +0000 | [diff] [blame] | 211 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 212 | /** \brief enumerate all entries |
Junxiao Shi | 9f6ca60 | 2016-08-15 04:50:29 +0000 | [diff] [blame] | 213 | * \return a range where every entry matches \p entrySelector |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 214 | * |
| 215 | * Example: |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 216 | * \code |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 217 | * auto&& enumerable = nt.fullEnumerate(); |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 218 | * for (const Entry& nte : enumerable) { |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 219 | * ... |
| 220 | * } |
| 221 | * \endcode |
Junxiao Shi | b30863e | 2016-08-15 21:32:01 +0000 | [diff] [blame] | 222 | * \note Iteration order is implementation-defined. |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 223 | * \warning If a name tree entry is inserted or deleted during the enumeration, |
| 224 | * it may cause the enumeration to skip entries or visit some entries twice. |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 225 | */ |
Junxiao Shi | 9f6ca60 | 2016-08-15 04:50:29 +0000 | [diff] [blame] | 226 | Range |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 227 | fullEnumerate(const EntrySelector& entrySelector = AnyEntry()) const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 228 | |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 229 | /** \brief enumerate all entries under a prefix |
Junxiao Shi | 9f6ca60 | 2016-08-15 04:50:29 +0000 | [diff] [blame] | 230 | * \return a range where every entry has a name that starts with \p prefix, |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 231 | * and matches \p entrySubTreeSelector. |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 232 | * |
| 233 | * Example: |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 234 | * \code |
| 235 | * Name name("/A/B/C"); |
| 236 | * auto&& enumerable = nt.partialEnumerate(name); |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 237 | * for (const Entry& nte : enumerable) { |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 238 | * BOOST_ASSERT(name.isPrefixOf(nte.getName())); |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 239 | * ... |
| 240 | * } |
| 241 | * \endcode |
Junxiao Shi | b30863e | 2016-08-15 21:32:01 +0000 | [diff] [blame] | 242 | * \note Iteration order is implementation-defined. |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 243 | * \warning If a name tree entry under \p prefix is inserted or deleted during the enumeration, |
| 244 | * it may cause the enumeration to skip entries or visit some entries twice. |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 245 | */ |
Junxiao Shi | 9f6ca60 | 2016-08-15 04:50:29 +0000 | [diff] [blame] | 246 | Range |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 247 | partialEnumerate(const Name& prefix, |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 248 | const EntrySubTreeSelector& entrySubTreeSelector = AnyEntrySubTree()) const; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 249 | |
Junxiao Shi | b30863e | 2016-08-15 21:32:01 +0000 | [diff] [blame] | 250 | /** \return an iterator to the beginning |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 251 | * \sa fullEnumerate |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 252 | */ |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 253 | const_iterator |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame] | 254 | begin() const |
| 255 | { |
| 256 | return fullEnumerate().begin(); |
| 257 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 258 | |
Junxiao Shi | b30863e | 2016-08-15 21:32:01 +0000 | [diff] [blame] | 259 | /** \return an iterator to the end |
| 260 | * \sa begin() |
Alexander Afanasyev | 09fc3d9 | 2015-01-03 02:02:37 -0800 | [diff] [blame] | 261 | */ |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 262 | const_iterator |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame] | 263 | end() const |
| 264 | { |
| 265 | return Iterator(); |
| 266 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 267 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 268 | private: |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame] | 269 | Hashtable m_ht; |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 270 | |
Junxiao Shi | b660b4c | 2016-08-06 20:47:44 +0000 | [diff] [blame] | 271 | friend class EnumerationImpl; |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 272 | }; |
| 273 | |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 274 | } // namespace name_tree |
| 275 | |
| 276 | using name_tree::NameTree; |
| 277 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 278 | } // namespace nfd |
| 279 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 280 | #endif // NFD_DAEMON_TABLE_NAME_TREE_HPP |