void MemTrie::insert(std::string const& _key, std::string const& _value) { if (_value.empty()) remove(_key); auto h = asNibbles(_key); m_root = m_root ? m_root->insert(&h, _value) : new TrieLeafNode(bytesConstRef(&h), _value); }
std::string const& MemTrie::at(std::string const& _key) const { if (!m_root) return c_nullString; auto h = asNibbles(_key); return m_root->at(bytesConstRef(&h)); }
void MemTrie::remove(std::string const& _key) { if (m_root) { auto h = asNibbles(_key); m_root = m_root->remove(&h); } }
h256 hash256(u256Map const& _s) { // build patricia tree. if (_s.empty()) return h256(); HexMap hexMap; for (auto i = _s.rbegin(); i != _s.rend(); ++i) hexMap[asNibbles(toBigEndianString(i->first))] = asString(rlp(i->second)); RLPStream s; hash256rlp(hexMap, hexMap.cbegin(), hexMap.cend(), 0, s); return sha3(s.out()); }
bytes rlp256(StringMap const& _s) { // build patricia tree. if (_s.empty()) return bytes(); HexMap hexMap; for (auto i = _s.rbegin(); i != _s.rend(); ++i) hexMap[asNibbles(i->first)] = i->second; RLPStream s; hash256aux(hexMap, hexMap.cbegin(), hexMap.cend(), 0, s); return s.out(); }