table: make name_tree::Node the sole owner of name_tree::Entry
This commit also improves name_tree::Entry test coverage.
refs #3687
Change-Id: I92375f29fbebab82c67da7dff2ea7a2952ba2cca
diff --git a/daemon/table/name-tree-hashtable.cpp b/daemon/table/name-tree-hashtable.cpp
index 1267f99..67eafcd 100644
--- a/daemon/table/name-tree-hashtable.cpp
+++ b/daemon/table/name-tree-hashtable.cpp
@@ -24,7 +24,6 @@
*/
#include "name-tree-hashtable.hpp"
-#include "name-tree-entry.hpp"
#include "core/logger.hpp"
#include "core/city-hash.hpp"
@@ -92,7 +91,7 @@
: hash(h)
, prev(nullptr)
, next(nullptr)
- , entry(make_shared<Entry>(name, this))
+ , entry(name, this)
{
}
@@ -182,7 +181,7 @@
size_t bucket = this->computeBucketIndex(h);
for (const Node* node = m_buckets[bucket]; node != nullptr; node = node->next) {
- if (node->hash == h && name.compare(0, prefixLen, node->entry->getName()) == 0) {
+ if (node->hash == h && name.compare(0, prefixLen, node->entry.getName()) == 0) {
NFD_LOG_TRACE("found " << name.getPrefix(prefixLen) << " hash=" << h << " bucket=" << bucket);
return {node, false};
}
@@ -195,7 +194,7 @@
Node* node = new Node(h, name.getPrefix(prefixLen));
this->attach(bucket, node);
- NFD_LOG_TRACE("insert " << node->entry->getName() << " hash=" << h << " bucket=" << bucket);
+ NFD_LOG_TRACE("insert " << node->entry.getName() << " hash=" << h << " bucket=" << bucket);
++m_size;
if (m_size > m_expandThreshold) {
@@ -230,10 +229,10 @@
Hashtable::erase(Node* node)
{
BOOST_ASSERT(node != nullptr);
- BOOST_ASSERT(node->entry->getParent() == nullptr);
+ BOOST_ASSERT(node->entry.getParent() == nullptr);
size_t bucket = this->computeBucketIndex(node->hash);
- NFD_LOG_TRACE("erase " << node->entry->getName() << " hash=" << node->hash << " bucket=" << bucket);
+ NFD_LOG_TRACE("erase " << node->entry.getName() << " hash=" << node->hash << " bucket=" << bucket);
this->detach(bucket, node);
delete node;