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