removed shared_ptr on TData, set minWork

This commit is contained in:
Brannon King 2019-08-28 14:04:29 -06:00 committed by Anthony Fieroni
parent 088d82ee44
commit 67753363f7
4 changed files with 15 additions and 19 deletions

View file

@ -147,11 +147,10 @@ public:
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008 consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
// The best chain should have at least this much work. // The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000607ca7e806c4c1e9"); //400000 consensus.nMinimumChainWork = uint256S("00000000000000000000000000000000000000000000024108e3204a44a57a5a"); //621000
// By default assume that the signatures in ancestors of this block are valid. // By default assume that the signatures in ancestors of this block are valid.
//consensus.defaultAssumeValid = uint256S("0xf0e56e70782af63ccb49c76e852540688755869ba59ec68cac9c04a6b4d9f5ca"); //400000 consensus.defaultAssumeValid = uint256S("7899464514d0d8854919e87eb234fd5f0c35d06418bd5fd3c1a8f7092b2a9317"); //620000
consensus.defaultAssumeValid = uint256S("0xa6bbb48f5343eb9b0287c22f3ea8b29f36cf10794a37f8a925a894d6f4519913"); //4000
/** /**
* The message start string is designed to be unlikely to occur in normal data. * The message start string is designed to be unlikely to occur in normal data.

View file

@ -148,8 +148,8 @@ struct CClaimTrieData
int nHeightOfLastTakeover = 0; int nHeightOfLastTakeover = 0;
// non-serialized data: // non-serialized data:
uint256 hash;
uint32_t flags = 0; uint32_t flags = 0;
uint256 hash;
CClaimTrieData() = default; CClaimTrieData() = default;
CClaimTrieData(CClaimTrieData&&) = default; CClaimTrieData(CClaimTrieData&&) = default;

View file

@ -109,7 +109,7 @@ template <bool IsConst>
typename CPrefixTrie<TKey, TData>::template Iterator<IsConst>::reference CPrefixTrie<TKey, TData>::Iterator<IsConst>::operator*() const typename CPrefixTrie<TKey, TData>::template Iterator<IsConst>::reference CPrefixTrie<TKey, TData>::Iterator<IsConst>::operator*() const
{ {
assert(!node.expired()); assert(!node.expired());
return TPair(name, *(node.lock()->data)); return TPair(name, node.lock()->data);
} }
template <typename TKey, typename TData> template <typename TKey, typename TData>
@ -117,7 +117,7 @@ template <bool IsConst>
typename CPrefixTrie<TKey, TData>::template Iterator<IsConst>::pointer CPrefixTrie<TKey, TData>::Iterator<IsConst>::operator->() const typename CPrefixTrie<TKey, TData>::template Iterator<IsConst>::pointer CPrefixTrie<TKey, TData>::Iterator<IsConst>::operator->() const
{ {
assert(!node.expired()); assert(!node.expired());
return node.lock()->data.get(); return &(node.lock()->data);
} }
template <typename TKey, typename TData> template <typename TKey, typename TData>
@ -132,7 +132,7 @@ template <bool IsConst>
TData& CPrefixTrie<TKey, TData>::Iterator<IsConst>::data() TData& CPrefixTrie<TKey, TData>::Iterator<IsConst>::data()
{ {
assert(!node.expired()); assert(!node.expired());
return *(node.lock()->data); return node.lock()->data;
} }
template <typename TKey, typename TData> template <typename TKey, typename TData>
@ -140,7 +140,7 @@ template <bool IsConst>
const TData& CPrefixTrie<TKey, TData>::Iterator<IsConst>::data() const const TData& CPrefixTrie<TKey, TData>::Iterator<IsConst>::data() const
{ {
assert(!node.expired()); assert(!node.expired());
return *(node.lock()->data); return node.lock()->data;
} }
template <typename TKey, typename TData> template <typename TKey, typename TData>
@ -223,7 +223,6 @@ std::shared_ptr<typename CPrefixTrie<TKey, TData>::Node>& CPrefixTrie<TKey, TDat
if (count == 0) { if (count == 0) {
++size; ++size;
it = children.emplace(key, std::make_shared<Node>()).first; it = children.emplace(key, std::make_shared<Node>()).first;
it->second->data = std::make_shared<TData>();
return it->second; return it->second;
} }
if (count < it->first.size()) { if (count < it->first.size()) {
@ -234,7 +233,6 @@ std::shared_ptr<typename CPrefixTrie<TKey, TData>::Node>& CPrefixTrie<TKey, TDat
++size; ++size;
it = children.emplace(prefix, std::make_shared<Node>()).first; it = children.emplace(prefix, std::make_shared<Node>()).first;
it->second->children.emplace(postfix, std::move(nodes)); it->second->children.emplace(postfix, std::move(nodes));
it->second->data = std::make_shared<TData>();
if (key.size() == count) if (key.size() == count)
return it->second; return it->second;
} }
@ -253,12 +251,12 @@ void CPrefixTrie<TKey, TData>::erase(const TKey& key, std::shared_ptr<Node>& nod
if (!find(key, node, cb)) if (!find(key, node, cb))
return; return;
nodes.back().second->data = std::make_shared<TData>(); nodes.back().second->data = {};
for (; nodes.size() > 1; nodes.pop_back()) { for (; nodes.size() > 1; nodes.pop_back()) {
// if we have only one child and no data ourselves, bring them up to our level // if we have only one child and no data ourselves, bring them up to our level
auto& cNode = nodes.back().second; auto& cNode = nodes.back().second;
auto onlyOneChild = cNode->children.size() == 1; auto onlyOneChild = cNode->children.size() == 1;
auto noData = cNode->data->empty(); auto noData = cNode->data.empty();
if (onlyOneChild && noData) { if (onlyOneChild && noData) {
auto child = cNode->children.begin(); auto child = cNode->children.begin();
auto& prefix = nodes.back().first; auto& prefix = nodes.back().first;
@ -286,7 +284,6 @@ void CPrefixTrie<TKey, TData>::erase(const TKey& key, std::shared_ptr<Node>& nod
template <typename TKey, typename TData> template <typename TKey, typename TData>
CPrefixTrie<TKey, TData>::CPrefixTrie() : size(0), root(std::make_shared<Node>()) CPrefixTrie<TKey, TData>::CPrefixTrie() : size(0), root(std::make_shared<Node>())
{ {
root->data = std::make_shared<TData>();
} }
template <typename TKey, typename TData> template <typename TKey, typename TData>
@ -294,7 +291,7 @@ template <typename TDataUni>
typename CPrefixTrie<TKey, TData>::iterator CPrefixTrie<TKey, TData>::insert(const TKey& key, TDataUni&& data) typename CPrefixTrie<TKey, TData>::iterator CPrefixTrie<TKey, TData>::insert(const TKey& key, TDataUni&& data)
{ {
auto& node = key.empty() ? root : insert(key, root); auto& node = key.empty() ? root : insert(key, root);
node->data = std::make_shared<TData>(std::forward<TDataUni>(data)); node->data = std::forward<TDataUni>(data);
return key.empty() ? begin() : iterator{key, node}; return key.empty() ? begin() : iterator{key, node};
} }
@ -320,7 +317,7 @@ typename CPrefixTrie<TKey, TData>::iterator CPrefixTrie<TKey, TData>::insert(CPr
auto& node = insert(key, shared); auto& node = insert(key, shared);
copy = iterator{name, node}; copy = iterator{name, node};
} }
copy.node.lock()->data = std::make_shared<TData>(std::forward<TDataUni>(data)); copy.node.lock()->data = std::forward<TDataUni>(data);
return copy; return copy;
} }
@ -393,7 +390,7 @@ bool CPrefixTrie<TKey, TData>::erase(const TKey& key)
{ {
auto size_was = height(); auto size_was = height();
if (key.empty()) { if (key.empty()) {
root->data = std::make_shared<TData>(); root->data = {};
} else { } else {
erase(key, root); erase(key, root);
} }
@ -404,7 +401,7 @@ template <typename TKey, typename TData>
void CPrefixTrie<TKey, TData>::clear() void CPrefixTrie<TKey, TData>::clear()
{ {
size = 0; size = 0;
root->data = std::make_shared<TData>(); root->data = {};
root->children.clear(); root->children.clear();
} }
@ -417,7 +414,7 @@ bool CPrefixTrie<TKey, TData>::empty() const
template <typename TKey, typename TData> template <typename TKey, typename TData>
std::size_t CPrefixTrie<TKey, TData>::height() const std::size_t CPrefixTrie<TKey, TData>::height() const
{ {
return size + (root->data->empty() ? 0 : 1); return size + (root->data.empty() ? 0 : 1);
} }
template <typename TKey, typename TData> template <typename TKey, typename TData>

View file

@ -29,7 +29,7 @@ class CPrefixTrie
Node(Node&& o) noexcept = default; Node(Node&& o) noexcept = default;
Node& operator=(Node&& o) noexcept = default; Node& operator=(Node&& o) noexcept = default;
Node& operator=(const Node&) = delete; Node& operator=(const Node&) = delete;
std::shared_ptr<TData> data; TData data;
}; };
using TChildren = decltype(Node::children); using TChildren = decltype(Node::children);