33 std::unordered_map<h256, std::string> MemoryDB::get()
const 38 std::unordered_map<h256, std::string> ret;
39 for (
auto const& i: m_main)
40 if (!m_enforceRefs || i.second.second > 0)
41 ret.insert(make_pair(i.first, i.second.first));
58 std::string MemoryDB::lookup(
h256 const& _h)
const 63 auto it = m_main.find(_h);
64 if (it != m_main.end())
66 if (!m_enforceRefs || it->second.second > 0)
67 return it->second.first;
69 cwarn <<
"Lookup required for value with refcount == 0. This is probably a critical trie issue" << _h;
74 bool MemoryDB::exists(
h256 const& _h)
const 79 auto it = m_main.find(_h);
80 if (it != m_main.end() && (!m_enforceRefs || it->second.second > 0))
90 auto it = m_main.find(_h);
91 if (it != m_main.end())
97 m_main[_h] = make_pair(_v.
toString(), 1);
99 dbdebug <<
"INST" << _h <<
"=>" << m_main[_h].second;
103 bool MemoryDB::kill(
h256 const& _h)
108 if (m_main.count(_h))
110 if (m_main[_h].second > 0)
122 dbdebug <<
"KILL" << _h <<
"=>" << m_main[_h].second;
137 auto it = m_aux.find(_h);
138 if (it != m_aux.end() && (!m_enforceRefs || it->second.second))
139 return it->second.first;
143 void MemoryDB::removeAux(
h256 const& _h)
148 m_aux[_h].second =
false;
156 m_aux[_h] = make_pair(_v.
toBytes(),
true);
159 void MemoryDB::purge()
165 for (
auto it = m_main.begin(); it != m_main.end(); )
166 if (it->second.second)
169 it = m_main.erase(it);
172 for (
auto it = m_aux.begin(); it != m_aux.end(); )
173 if (it->second.second)
176 it = m_aux.erase(it);
185 for (
auto const& i: m_main)
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::unordered_map< h256, std::pair< std::string, unsigned > > m_main
std::hash for asio::adress
std::vector< byte > bytes
std::vector< unsigned char > toBytes() const
boost::shared_lock< boost::shared_mutex > ReadGuard
boost::unique_lock< boost::shared_mutex > WriteGuard
std::unordered_set< h256 > h256Hash
std::unordered_map< h256, std::pair< bytes, bool > > m_aux
std::string toString() const