table: delete deprecated functions in NameTree

NameTree::eraseEntryIfEmpty is renamed to eraseIfEmpty;
the deprecated overload that accepts shared_ptr<name_tree::Entry> is deleted.
name_tree::Entry::getPrefix is deleted in favor of getName.

This commit also improves Doxygen in NameTree class.

refs #3687

Change-Id: Ia98ca676ce6d3bc7b2e97328adccac911c8167d7
This commit is contained in:
Junxiao Shi committed 2016-08-09 03:50:56 +00:00
1 parent f9f7cf35ae
commit e3cf285ee7
10 files changed
+114 -124

No files matched your search

+2 -2
View File
@@ -44,7 +44,7 @@ cleanupOnFaceRemoval(NameTree& nt, Fib& fib, Pit& pit, const Face& face)
}
if (nte.getFibEntry() == nullptr && !nte.hasPitEntries()) {
maybeEmptyNtes.emplace(nte.getPrefix().size(), const_pointer_cast<name_tree::Entry>(nte.shared_from_this()));
maybeEmptyNtes.emplace(nte.getName().size(), const_pointer_cast<name_tree::Entry>(nte.shared_from_this()));
}
}
@@ -53,7 +53,7 @@ cleanupOnFaceRemoval(NameTree& nt, Fib& fib, Pit& pit, const Face& face)
shared_ptr<name_tree::Entry> nte = i->second.lock();
// nte may have been erased when its last child is erased
if (nte != nullptr) {
nt.eraseEntryIfEmpty(nte);
nt.eraseIfEmpty(nte.get());
}
}
}
+1 -1
View File
@@ -136,7 +136,7 @@ Fib::erase(shared_ptr<name_tree::Entry> nte, bool canDeleteNte)
nte->setFibEntry(nullptr);
if (canDeleteNte) {
m_nameTree.eraseEntryIfEmpty(nte);
m_nameTree.eraseIfEmpty(nte.get());
}
--m_nItems;
}
+2 -2
View File
@@ -45,7 +45,7 @@ Measurements::get(name_tree::Entry& nte)
return *entry;
}
nte.setMeasurementsEntry(make_unique<Entry>(nte.getPrefix()));
nte.setMeasurementsEntry(make_unique<Entry>(nte.getName()));
++m_nItems;
entry = nte.getMeasurementsEntry();
@@ -165,7 +165,7 @@ Measurements::cleanup(Entry& entry)
BOOST_ASSERT(nte != nullptr);
nte->setMeasurementsEntry(nullptr);
m_nameTree.eraseEntryIfEmpty(nte);
m_nameTree.eraseIfEmpty(nte.get());
--m_nItems;
}
-7
View File
@@ -48,13 +48,6 @@ public:
return m_name;
}
/// \deprecated
const Name&
getPrefix() const
{
return this->getName();
}
/** \return entry of getName().getPrefix(-1)
* \retval nullptr this entry is the root entry, i.e. getName() == Name()
*/
+2 -2
View File
@@ -90,12 +90,12 @@ operator<<(std::ostream& os, const Iterator& i)
return os << "uninitialized";
}
os << "entry=" << i.m_entry->getPrefix();
os << "entry=" << i.m_entry->getName();
if (i.m_ref == nullptr) {
os << " ref=null";
}
else {
os << " ref=" << i.m_ref->getPrefix();
os << " ref=" << i.m_ref->getName();
}
os << " state=" << i.m_state;
return os;
+8 -9
View File
@@ -77,12 +77,12 @@ NameTree::lookup(const pit::Entry& pitEntry)
return nullptr;
}
if (nte->getPrefix().size() == pitEntry.getName().size()) {
if (nte->getName().size() == pitEntry.getName().size()) {
return nte;
}
BOOST_ASSERT(pitEntry.getName().at(-1).isImplicitSha256Digest());
BOOST_ASSERT(nte->getPrefix() == pitEntry.getName().getPrefix(-1));
BOOST_ASSERT(nte->getName() == pitEntry.getName().getPrefix(-1));
return this->lookup(pitEntry.getName());
}
@@ -103,7 +103,7 @@ NameTree::lookup(const strategy_choice::Entry& strategyChoiceEntry) const
}
size_t
NameTree::eraseEntryIfEmpty(Entry* entry)
NameTree::eraseIfEmpty(Entry* entry)
{
BOOST_ASSERT(entry != nullptr);
@@ -167,21 +167,20 @@ NameTree::findLongestPrefixMatch(const pit::Entry& pitEntry) const
{
shared_ptr<Entry> nte = this->getEntry(pitEntry);
BOOST_ASSERT(nte != nullptr);
if (nte->getPrefix().size() == pitEntry.getName().size()) {
if (nte->getName().size() == pitEntry.getName().size()) {
return nte;
}
BOOST_ASSERT(pitEntry.getName().at(-1).isImplicitSha256Digest());
BOOST_ASSERT(nte->getPrefix() == pitEntry.getName().getPrefix(-1));
BOOST_ASSERT(nte->getName() == pitEntry.getName().getPrefix(-1));
shared_ptr<Entry> exact = this->findExactMatch(pitEntry.getName());
return exact == nullptr ? nte : exact;
}
boost::iterator_range<NameTree::const_iterator>
NameTree::findAllMatches(const Name& prefix,
const EntrySelector& entrySelector) const
NameTree::findAllMatches(const Name& name, const EntrySelector& entrySelector) const
{
NFD_LOG_TRACE("NameTree::findAllMatches" << prefix);
NFD_LOG_TRACE("NameTree::findAllMatches" << name);
// As we are using Name Prefix Hash Table, and the current LPM() is
// implemented as starting from full name, and reduce the number of
@@ -189,7 +188,7 @@ NameTree::findAllMatches(const Name& prefix,
// For trie-like design, it could be more efficient by walking down the
// trie from the root node.
shared_ptr<Entry> entry = findLongestPrefixMatch(prefix, entrySelector);
shared_ptr<Entry> entry = findLongestPrefixMatch(name, entrySelector);
return {Iterator(make_shared<PrefixMatchImpl>(*this, entrySelector), entry.get()), end()};
}
+73 -73
View File
@@ -31,6 +31,8 @@
namespace nfd {
namespace name_tree {
/** \brief a common index structure for FIB, PIT, StrategyChoice, and Measurements
*/
class NameTree : noncopyable
{
public:
@@ -40,7 +42,7 @@ public:
NameTree(size_t nBuckets = 1024);
public: // information
/** \brief Get the number of occupied entries in the Name Tree
/** \return number of name tree entries
*/
size_t
size() const
@@ -48,10 +50,7 @@ public: // information
return m_ht.size();
}
/** \brief Get the number of buckets in the Name Tree (NPHT)
*
* The number of buckets is the one that used to create the hash
* table, i.e., m_nBuckets.
/** \return number of hashtable buckets
*/
size_t
getNBuckets() const
@@ -59,7 +58,7 @@ public: // information
return m_ht.getNBuckets();
}
/** \return Name Tree Entry on which a table entry is attached
/** \return entry on which a table entry is attached
*/
template<typename ENTRY>
shared_ptr<Entry>
@@ -69,149 +68,152 @@ public: // information
}
public: // mutation
/** \brief Look for the Name Tree Entry that contains this name prefix.
*
* Starts from the shortest name prefix, and then increase the
* number of name components by one each time. All non-existing Name Tree
* Entries will be created.
*
* \param name The querying name prefix.
* \return The pointer to the Name Tree Entry that contains this full name prefix.
/** \brief find or insert an entry with specified name
* \param name a name prefix
* \return an entry with \p name
* \post an entry with \p name and all ancestors are created
* \note Existing iterators are unaffected.
*/
shared_ptr<Entry>
lookup(const Name& name);
/** \brief get NameTree entry from FIB entry
*
* This is equivalent to .lookup(fibEntry.getPrefix())
/** \brief equivalent to .lookup(fibEntry.getPrefix())
* \note This overload is more efficient than .lookup(const Name&) in common cases.
*/
shared_ptr<Entry>
lookup(const fib::Entry& fibEntry) const;
/** \brief get NameTree entry from PIT entry
*
* This is equivalent to .lookup(pitEntry.getName()).
/** \brief equivalent to .lookup(pitEntry.getName()).
* \note This overload is more efficient than .lookup(const Name&) in common cases.
*/
shared_ptr<Entry>
lookup(const pit::Entry& pitEntry);
/** \brief get NameTree entry from Measurements entry
*
* This is equivalent to .lookup(measurementsEntry.getName())
/** \brief equivalent to .lookup(measurementsEntry.getName())
* \note This overload is more efficient than .lookup(const Name&) in common cases.
*/
shared_ptr<Entry>
lookup(const measurements::Entry& measurementsEntry) const;
/** \brief get NameTree entry from StrategyChoice entry
*
* This is equivalent to .lookup(strategyChoiceEntry.getName())
/** \brief equivalent to .lookup(strategyChoiceEntry.getName())
* \note This overload is more efficient than .lookup(const Name&) in common cases.
*/
shared_ptr<Entry>
lookup(const strategy_choice::Entry& strategyChoiceEntry) const;
/** \brief Delete a Name Tree Entry if this entry is empty.
* \param entry The entry to be deleted if empty.
* \note This function must be called after a table entry is detached from Name Tree
* entry. The function deletes a Name Tree entry if nothing is attached to it and
* it has no children, then repeats the same process on its ancestors.
/** \brief delete the entry if it is empty
* \param entry a valid entry
* \return number of deleted entries
* \sa Entry::isEmpty()
* \post If the entry is empty, it's deleted.
* Ancestors of the entry are also deleted if they become empty.
* \note This function must be called after detaching a table entry from a name tree entry,
* \note Existing iterators, except those pointing to deleted entries, are unaffected.
*/
size_t
eraseEntryIfEmpty(Entry* entry);
/// \deprecated
bool
eraseEntryIfEmpty(shared_ptr<Entry> entry)
{
BOOST_ASSERT(entry != nullptr);
return this->eraseEntryIfEmpty(entry.get()) > 0;
}
eraseIfEmpty(Entry* entry);
public: // matching
/** \brief Exact match lookup for the given name prefix.
* \return nullptr if this prefix is not found; otherwise return the Name Tree Entry address
/** \brief exact match lookup
* \return entry with \p name, or nullptr if it does not exist
*/
shared_ptr<Entry>
findExactMatch(const Name& name) const;
/** \brief Longest prefix matching for the given name
*
* Starts from the full name string, reduce the number of name component
* by one each time, until an Entry is found.
/** \brief longest prefix matching
* \return entry whose name is a prefix of \p name and passes \p entrySelector,
* where no other entry with a longer name satisfies those requirements;
* or nullptr if no entry satisfying those requirements exists
*/
shared_ptr<Entry>
findLongestPrefixMatch(const Name& name,
const EntrySelector& entrySelector = AnyEntry()) const;
/** \brief equivalent to .findLongestPrefixMatch(entry->getName(), entrySelector)
* \note This overload is more efficient than .findLongestPrefixMatch(const Name&)
* in common cases.
*/
shared_ptr<Entry>
findLongestPrefixMatch(shared_ptr<Entry> entry,
const EntrySelector& entrySelector = AnyEntry()) const;
/** \brief longest prefix matching for Interest name of the PIT entry
*
* This is equivalent to .findLongestPrefixMatch(pitEntry.getName(), AnyEntry()).
/** \brief equivalent to .findLongestPrefixMatch(pitEntry.getName(), AnyEntry())
* \note This overload is more efficient than .findLongestPrefixMatch(const Name&)
* in common cases.
*/
shared_ptr<Entry>
findLongestPrefixMatch(const pit::Entry& pitEntry) const;
/** \brief Enumerate all the name prefixes that satisfy the prefix and entrySelector
/** \brief all-prefixes match lookup
* \return an unspecified type that have .begin() and .end() methods
* and is usable with range-based for
* and is usable with range-based for.
* Every entry in the range has a name that is a prefix of \p name ,
* and matches \p entrySelector.
*
* Example:
* \code{.cpp}
* auto&& allMatches = nt.findAllMatches(Name("/A/B/C"));
* \code
* Name name("/A/B/C");
* auto&& allMatches = nt.findAllMatches(name);
* for (const Entry& nte : allMatches) {
* BOOST_ASSERT(nte.getName().isPrefixOf(name));
* ...
* }
* \endcode
* \note Iteration order is implementation-specific and is undefined
* \note The returned iterator may get invalidated when NameTree is modified
* \note Iteration order is implementation-specific and is undefined.
* \warning If a name tree entry whose name is a prefix of \p name is inserted
* during the enumeration, it may or may not be visited.
* If a name tree entry whose name is a prefix of \p name is deleted
* during the enumeration, undefined behavior may occur.
*/
boost::iterator_range<const_iterator>
findAllMatches(const Name& prefix,
findAllMatches(const Name& name,
const EntrySelector& entrySelector = AnyEntry()) const;
public: // enumeration
/** \brief Enumerate all entries, optionally filtered by an EntrySelector.
/** \brief enumerate all entries
* \return an unspecified type that have .begin() and .end() methods
* and is usable with range-based for
* and is usable with range-based for.
* Every entry in the range matches \p entrySelector.
*
* Example:
* \code{.cpp}
* \code
* auto&& enumerable = nt.fullEnumerate();
* for (const Entry& nte : enumerable) {
* ...
* }
* \endcode
* \note Iteration order is implementation-specific and is undefined
* \note The returned iterator may get invalidated when NameTree is modified
* \note Iteration order is implementation-specific and is undefined.
* \warning If a name tree entry is inserted or deleted during the enumeration,
* it may cause the enumeration to skip entries or visit some entries twice.
*/
boost::iterator_range<const_iterator>
fullEnumerate(const EntrySelector& entrySelector = AnyEntry()) const;
/** \brief Enumerate all entries under a prefix, optionally filtered by an EntrySubTreeSelector.
/** \brief enumerate all entries under a prefix
* \return an unspecified type that have .begin() and .end() methods
* and is usable with range-based for
* and is usable with range-based for.
* Every entry in the range has a name that starts with \p prefix,
* and matches \p entrySubTreeSelector.
*
* Example:
* \code{.cpp}
* auto&& enumerable = nt.partialEnumerate(Name("/A/B/C"));
* \code
* Name name("/A/B/C");
* auto&& enumerable = nt.partialEnumerate(name);
* for (const Entry& nte : enumerable) {
* BOOST_ASSERT(name.isPrefixOf(nte.getName()));
* ...
* }
* \endcode
* \note Iteration order is implementation-specific and is undefined
* \note The returned iterator may get invalidated when NameTree is modified
* \note Iteration order is implementation-specific and is undefined.
* \warning If a name tree entry under \p prefix is inserted or deleted during the enumeration,
* it may cause the enumeration to skip entries or visit some entries twice.
*/
boost::iterator_range<const_iterator>
partialEnumerate(const Name& prefix,
const EntrySubTreeSelector& entrySubTreeSelector = AnyEntrySubTree()) const;
/** \brief Get an iterator pointing to the first NameTree entry
* \note Iteration order is implementation-specific and is undefined
* \note The returned iterator may get invalidated when NameTree is modified
/** \return an iterator to enumerate all entries
* \sa fullEnumerate
*/
const_iterator
begin() const
@@ -219,9 +221,7 @@ public: // enumeration
return fullEnumerate().begin();
}
/** \brief Get an iterator referring to the past-the-end FIB entry
* \note Iteration order is implementation-specific and is undefined
* \note The returned iterator may get invalidated when NameTree is modified
/** \return a past-the-end iterator
*/
const_iterator
end() const
+1 -1
View File
@@ -137,7 +137,7 @@ Pit::erase(shared_ptr<pit::Entry> entry, bool canDeleteNte)
nte->erasePitEntry(entry);
if (canDeleteNte) {
m_nameTree.eraseEntryIfEmpty(nte);
m_nameTree.eraseIfEmpty(nte.get());
}
--m_nItems;
}
+2 -2
View File
@@ -145,7 +145,7 @@ StrategyChoice::erase(const Name& prefix)
this->changeStrategy(*entry, oldStrategy, parentStrategy);
nte->setStrategyChoiceEntry(nullptr);
m_nameTree.eraseEntryIfEmpty(nte);
m_nameTree.eraseIfEmpty(nte.get());
--m_nItems;
}
@@ -229,7 +229,7 @@ StrategyChoice::setDefaultStrategy(unique_ptr<Strategy> strategy)
static inline void
clearStrategyInfo(const name_tree::Entry& nte)
{
NFD_LOG_TRACE("clearStrategyInfo " << nte.getPrefix());
NFD_LOG_TRACE("clearStrategyInfo " << nte.getName());
for (const shared_ptr<pit::Entry>& pitEntry : nte.getPitEntries()) {
pitEntry->clearStrategyInfo();
+23 -25
View File
@@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(NameTreeEntry)
auto node = make_unique<Node>(0, prefix);
shared_ptr<Entry> npe = node->entry;
BOOST_CHECK_EQUAL(npe->getPrefix(), prefix);
BOOST_CHECK_EQUAL(npe->getName(), prefix);
// examine all the get methods
@@ -312,7 +312,7 @@ BOOST_AUTO_TEST_CASE(Basic)
bool eraseResult = false;
temp = nt.findExactMatch(nameABC);
if (temp != nullptr)
eraseResult = nt.eraseEntryIfEmpty(temp);
eraseResult = nt.eraseIfEmpty(temp.get());
BOOST_CHECK_EQUAL(nt.size(), 6);
BOOST_CHECK(nt.findExactMatch(nameABC) == nullptr);
BOOST_CHECK_EQUAL(eraseResult, true);
@@ -320,20 +320,18 @@ BOOST_AUTO_TEST_CASE(Basic)
eraseResult = false;
temp = nt.findExactMatch(nameABCLPM);
if (temp != nullptr)
eraseResult = nt.eraseEntryIfEmpty(temp);
eraseResult = nt.eraseIfEmpty(temp.get());
BOOST_CHECK(temp == nullptr);
BOOST_CHECK_EQUAL(nt.size(), 6);
BOOST_CHECK_EQUAL(eraseResult, false);
// nt.dump(std::cout);
nt.lookup(nameABC);
BOOST_CHECK_EQUAL(nt.size(), 7);
eraseResult = false;
temp = nt.findExactMatch(nameABC);
if (temp != nullptr)
eraseResult = nt.eraseEntryIfEmpty(temp);
eraseResult = nt.eraseIfEmpty(temp.get());
BOOST_CHECK_EQUAL(nt.size(), 6);
BOOST_CHECK_EQUAL(eraseResult, true);
BOOST_CHECK(nt.findExactMatch(nameABC) == nullptr);
@@ -350,22 +348,22 @@ BOOST_AUTO_TEST_CASE(Basic)
// try to erase /a/b/c, should return false
temp = nt.findExactMatch(nameABC);
BOOST_CHECK_EQUAL(temp->getPrefix(), nameABC);
eraseResult = nt.eraseEntryIfEmpty(temp);
BOOST_CHECK_EQUAL(temp->getName(), nameABC);
eraseResult = nt.eraseIfEmpty(temp.get());
BOOST_CHECK_EQUAL(eraseResult, false);
temp = nt.findExactMatch(nameABC);
BOOST_CHECK_EQUAL(temp->getPrefix(), nameABC);
BOOST_CHECK_EQUAL(temp->getName(), nameABC);
temp = nt.findExactMatch(nameABD);
if (temp != nullptr)
nt.eraseEntryIfEmpty(temp);
nt.eraseIfEmpty(temp.get());
BOOST_CHECK_EQUAL(nt.size(), 8);
}
/** \brief verify a NameTree enumeration contains expected entries
*
* Example:
* \code{.cpp}
* \code
* auto& enumerable = ...;
* EnumerationVerifier(enumerable)
* .expect("/A")
@@ -381,7 +379,7 @@ public:
EnumerationVerifier(Enumerable&& enumerable)
{
for (const Entry& entry : enumerable) {
const Name& name = entry.getPrefix();
const Name& name = entry.getName();
BOOST_CHECK_MESSAGE(m_names.insert(name).second, "duplicate Name " << name);
}
}
@@ -497,7 +495,7 @@ BOOST_AUTO_TEST_CASE(OnlyA)
// Accept "root" nameA only
auto&& enumerable = nt.partialEnumerate("/a", [] (const Entry& entry) {
return std::make_pair(entry.getPrefix() == "/a", true);
return std::make_pair(entry.getName() == "/a", true);
});
EnumerationVerifier(enumerable)
@@ -511,7 +509,7 @@ BOOST_AUTO_TEST_CASE(ExceptA)
// Accept anything except "root" nameA
auto&& enumerable = nt.partialEnumerate("/a", [] (const Entry& entry) {
return std::make_pair(entry.getPrefix() != "/a", true);
return std::make_pair(entry.getName() != "/a", true);
});
EnumerationVerifier(enumerable)
@@ -527,7 +525,7 @@ BOOST_AUTO_TEST_CASE(NoNameANoSubTreeAB)
// No NameA
// No SubTree from NameAB
auto&& enumerable = nt.partialEnumerate("/a", [] (const Entry& entry) {
return std::make_pair(entry.getPrefix() != "/a", entry.getPrefix() != "/a/b");
return std::make_pair(entry.getName() != "/a", entry.getName() != "/a/b");
});
EnumerationVerifier(enumerable)
@@ -545,7 +543,7 @@ BOOST_AUTO_TEST_CASE(NoNameANoSubTreeAC)
// No NameA
// No SubTree from NameAC
auto&& enumerable = nt.partialEnumerate("/a", [] (const Entry& entry) {
return std::make_pair(entry.getPrefix() != "/a", entry.getPrefix() != "/a/c");
return std::make_pair(entry.getName() != "/a", entry.getName() != "/a/c");
});
EnumerationVerifier(enumerable)
@@ -562,7 +560,7 @@ BOOST_AUTO_TEST_CASE(NoSubTreeA)
// No Subtree from NameA
auto&& enumerable = nt.partialEnumerate("/a", [] (const Entry& entry) {
return std::make_pair(true, entry.getPrefix() != "/a");
return std::make_pair(true, entry.getName() != "/a");
});
EnumerationVerifier(enumerable)
@@ -593,7 +591,7 @@ BOOST_AUTO_TEST_CASE(Example)
bool visitEntry = false;
bool visitChildren = false;
Name name = entry.getPrefix();
Name name = entry.getName();
if (name == "/" || name == "/A/B" || name == "/A/B/C" || name == "/A/D") {
visitEntry = true;
@@ -645,7 +643,7 @@ BOOST_AUTO_TEST_CASE(HashTableResizeShrink)
BOOST_CHECK_EQUAL(nameTree.size(), 9);
BOOST_CHECK_EQUAL(nameTree.getNBuckets(), 32);
nameTree.eraseEntryIfEmpty(entry);
nameTree.eraseIfEmpty(entry.get());
BOOST_CHECK_EQUAL(nameTree.size(), 0);
BOOST_CHECK_EQUAL(nameTree.getNBuckets(), 16);
}
@@ -660,8 +658,8 @@ BOOST_AUTO_TEST_CASE(SurvivedIteratorAfterLookup)
Name nameB("/A/B");
std::set<Name> seenNames;
for (NameTree::const_iterator it = nt.begin(); it != nt.end(); ++it) {
BOOST_CHECK(seenNames.insert(it->getPrefix()).second);
if (it->getPrefix() == nameB) {
BOOST_CHECK(seenNames.insert(it->getName()).second);
if (it->getName() == nameB) {
nt.lookup("/D");
}
}
@@ -676,7 +674,7 @@ BOOST_AUTO_TEST_CASE(SurvivedIteratorAfterLookup)
BOOST_CHECK(seenNames.size() == 5);
}
// .eraseEntryIfEmpty should not invalidate iterator
// .eraseIfEmpty should not invalidate iterator
BOOST_AUTO_TEST_CASE(SurvivedIteratorAfterErase)
{
NameTree nt;
@@ -688,9 +686,9 @@ BOOST_AUTO_TEST_CASE(SurvivedIteratorAfterErase)
Name nameD("/A/D");
std::set<Name> seenNames;
for (NameTree::const_iterator it = nt.begin(); it != nt.end(); ++it) {
BOOST_CHECK(seenNames.insert(it->getPrefix()).second);
if (it->getPrefix() == nameD) {
nt.eraseEntryIfEmpty(nt.findExactMatch("/A/F/G")); // /A/F/G and /A/F are erased
BOOST_CHECK(seenNames.insert(it->getName()).second);
if (it->getName() == nameD) {
nt.eraseIfEmpty(nt.findExactMatch("/A/F/G").get()); // /A/F/G and /A/F are erased
}
}