CatapultServer  v0.5.0.1 (Elephant)
MemoryDataSource.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "DataSourceVerbosity.h"
23 #include "TreeNode.h"
24 #include "catapult/utils/Hashers.h"
25 #include "catapult/functions.h"
26 #include <unordered_map>
27 
28 namespace catapult { namespace tree {
29 
32  public:
35 
36  public:
38  size_t size() const;
39 
40  public:
42  std::unique_ptr<const TreeNode> get(const Hash256& hash) const;
43 
45  void forEach(const consumer<const TreeNode&>& consumer) const;
46 
47  public:
49  void set(const LeafTreeNode& node);
50 
52  void set(const BranchTreeNode& node);
53 
55  void clear();
56 
57  private:
58  template<typename TNode>
59  void save(const TNode& node) {
60  // explicitly call hash() before emplace to ensure cached value is used
61  // (and avoid undefined behavior of parameter evaluation order)
62  auto nodeHash = node.hash();
63  m_nodes.emplace(nodeHash, std::make_unique<TreeNode>(node));
64  }
65 
66  private:
68  std::unordered_map<Hash256, std::unique_ptr<TreeNode>, utils::ArrayHasher<Hash256>> m_nodes;
69  };
70 }}
catapult::tree::BranchTreeNode::path
const TreeNodePath & path() const
Gets the node path.
Definition: TreeNode.cpp:90
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::tree::MemoryDataSource::clear
void clear()
Clears all nodes.
Definition: MemoryDataSource.cpp:64
catapult::tree::MemoryDataSource::MemoryDataSource
MemoryDataSource(DataSourceVerbosity verbosity=DataSourceVerbosity::Off)
Creates a data source with specified verbosity.
Definition: MemoryDataSource.cpp:27
Parser.debug
def debug(*args)
Definition: Parser.py:46
catapult::tree::MemoryDataSource::set
void set(const LeafTreeNode &node)
Saves a leaf tree node.
Definition: MemoryDataSource.cpp:44
catapult::tree::DataSourceVerbosity::Verbose
Verbose messages.
catapult::tree::MemoryDataSource::get
std::unique_ptr< const TreeNode > get(const Hash256 &hash) const
Gets the tree node associated with hash.
Definition: MemoryDataSource.cpp:34
TreeNode.h
functions.h
catapult::tree::LeafTreeNode::value
const Hash256 & value() const
Gets the node value.
Definition: TreeNode.cpp:72
catapult::tree::LeafTreeNode::path
const TreeNodePath & path() const
Gets the node path.
Definition: TreeNode.cpp:68
catapult::tree::MemoryDataSource::m_nodes
std::unordered_map< Hash256, std::unique_ptr< TreeNode >, utils::ArrayHasher< Hash256 > > m_nodes
Definition: MemoryDataSource.h:68
catapult::tree::MemoryDataSource::m_isVerbose
bool m_isVerbose
Definition: MemoryDataSource.h:67
catapult::tree::MemoryDataSource::forEach
void forEach(const consumer< const TreeNode & > &consumer) const
Gets all nodes and passes them to consumer.
Definition: MemoryDataSource.cpp:39
HexFormatter.h
catapult::tree::BranchTreeNode::hash
const Hash256 & hash() const
Gets the hash representation of this node.
Definition: TreeNode.cpp:116
catapult::tree::LeafTreeNode
Represents a leaf tree node.
Definition: TreeNode.h:34
catapult::tree::MemoryDataSource::size
size_t size() const
Gets the number of saved nodes.
Definition: MemoryDataSource.cpp:30
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::tree::DataSourceVerbosity
DataSourceVerbosity
Data source verbosity.
Definition: DataSourceVerbosity.h:26
Hashers.h
DataSourceVerbosity.h
Logging.h
catapult::utils::ByteArray
Base class for wrappers of byte array types, to provide some type-safety.
Definition: ByteArray.h:29
catapult::tree::MemoryDataSource
A patricia tree memory data source.
Definition: MemoryDataSource.h:31
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::utils::ArrayHasher
Definition: Hashers.h:32
catapult::tree::BranchTreeNode
Represents a branch tree node.
Definition: TreeNode.h:60
catapult::tree::LeafTreeNode::hash
const Hash256 & hash() const
Gets the hash representation of this node.
Definition: TreeNode.cpp:76
MemoryDataSource.h
catapult::tree::MemoryDataSource::save
void save(const TNode &node)
Definition: MemoryDataSource.h:59
catapult::tree::DataSourceVerbosity::Off
No messages.
catapult::tree::BranchTreeNode::numLinks
size_t numLinks() const
Gets the number of links set in this node.
Definition: TreeNode.cpp:94