table: reorganize PIT implementation
Merge pit-{face,in,out}-record.{cpp,hpp} into pit-entry.{cpp,hpp}
and merge pit-iterator.{cpp,hpp} into pit.{cpp,hpp}.
Rename get{In,Out}Record() to find{In,Out}Record(), following the
typical C++ pattern of using the verb "find" for functions that
return iterators.
No functional changes.
Change-Id: I6740dd6cfe92ca477938ab8dc2f6271fd8b6cc26
diff --git a/daemon/table/pit.cpp b/daemon/table/pit.cpp
index b731df0..f2c7684 100644
--- a/daemon/table/pit.cpp
+++ b/daemon/table/pit.cpp
@@ -27,10 +27,18 @@
namespace nfd::pit {
-static inline bool
-nteHasPitEntries(const name_tree::Entry& nte)
+Iterator&
+Iterator::operator++()
{
- return nte.hasPitEntries();
+ BOOST_ASSERT(m_ntIt != NameTree::const_iterator());
+ BOOST_ASSERT(m_iPitEntry < m_ntIt->getPitEntries().size());
+
+ if (++m_iPitEntry >= m_ntIt->getPitEntries().size()) {
+ ++m_ntIt;
+ m_iPitEntry = 0;
+ BOOST_ASSERT(m_ntIt == NameTree::const_iterator() || m_ntIt->hasPitEntries());
+ }
+ return *this;
}
Pit::Pit(NameTree& nameTree)
@@ -44,7 +52,7 @@
// determine which NameTree entry should the PIT entry be attached onto
const Name& name = interest.getName();
bool hasDigest = name.size() > 0 && name[-1].isImplicitSha256Digest();
- size_t nteDepth = name.size() - static_cast<int>(hasDigest);
+ size_t nteDepth = name.size() - static_cast<size_t>(hasDigest);
nteDepth = std::min(nteDepth, NameTree::getMaxDepth());
// ensure NameTree entry exists
@@ -81,6 +89,12 @@
return {entry, true};
}
+static bool
+nteHasPitEntries(const name_tree::Entry& nte)
+{
+ return nte.hasPitEntries();
+}
+
DataMatchResult
Pit::findAllDataMatches(const Data& data) const
{
@@ -115,7 +129,7 @@
{
BOOST_ASSERT(entry != nullptr);
- auto in = entry->getInRecord(face);
+ auto in = entry->findInRecord(face);
if (in != entry->in_end()) {
entry->deleteInRecord(in);
}