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