49 cout <<
"Aleph-w PersistentHashMap Example" << endl;
50 cout <<
"=================================" << endl;
58 cout <<
"m1 has " << m1.
size() <<
" bindings." << endl;
60 assert(m1.contains(
"apple"));
61 assert(*m1.find(
"orange") == 20);
67 auto duplicate = m1.insert(
"apple", 15);
68 assert(*duplicate.find(
"apple") == 10);
71 auto m2 = m1.insert_or_assign(
"apple", 15).insert(
"grape", 40);
73 cout <<
"m2 has " << m2.size() <<
" bindings after update/insert." << endl;
75 assert(*m2.find(
"apple") == 15);
78 assert(*m1.find(
"apple") == 10);
79 assert(!m1.contains(
"grape"));
81 auto m3 = m2.erase(
"orange").erase(
"banana");
83 cout <<
"m3 has " << m3.size() <<
" bindings after erasing." << endl;
84 assert(!m3.contains(
"orange"));
85 assert(m3.contains(
"apple"));
87 assert(m2.contains(
"orange"));
92 cout <<
"All persistent structural-sharing invariants are valid." << endl;
Immutable unordered map backed by a Hash Array Mapped Trie (HAMT).
bool is_empty() const noexcept
Return true when this version has no bindings.
PersistentHashMap insert(const Key &key, const T &value) const
Return a new version with key inserted if absent.
size_t size() const noexcept
Return the number of bindings stored in this version.
Main namespace for Aleph-w library functions.
Immutable path-copying hash map backed by a HAMT.