|
| | PersistentTreapMap (Compare cmp=Compare()) |
| | Construct an empty persistent map.
|
| |
| bool | is_empty () const noexcept |
| | Return true when the map has no bindings.
|
| |
| size_t | size () const noexcept |
| | Return the number of key/value bindings in this version.
|
| |
| const T * | find (const Key &key) const |
| | Find a mapped value.
|
| |
| bool | contains (const Key &key) const |
| | Test whether key is present.
|
| |
template<typename KArg , typename VArg >
requires std::constructible_from<Key, KArg &&> |
| and std::constructible_from< T, VArg && > PersistentTreapMap | insert (KArg &&key, VArg &&value) const |
| | Return a new version with a binding inserted if absent.
|
| |
template<typename KArg , typename VArg >
requires std::constructible_from<Key, KArg &&> |
| and std::constructible_from< T, VArg && > PersistentTreapMap | insert_or_assign (KArg &&key, VArg &&value) const |
| | Return a new version with key assigned to value.
|
| |
| PersistentTreapMap | erase (const Key &key) const |
| | Return a new version without key.
|
| |
| std::pair< PersistentTreapMap, PersistentTreapMap > | split (const Key &pivot) const |
| | Split this version around pivot.
|
| |
| PersistentTreapMap | join (const PersistentTreapMap &right) const |
| | Join this version with right.
|
| |
| Array< Key > | keys () const |
| | Return all keys in sorted order.
|
| |
| Array< std::pair< Key, T > > | items () const |
| | Return all key/value bindings in sorted-key order.
|
| |
| bool | verify () const |
| | Verify treap, BST and cached-size invariants.
|
| |
|
| static NodePtr | make_node (std::shared_ptr< const Key > key, std::shared_ptr< const T > value, const std::uint64_t priority, NodePtr left, NodePtr right) |
| |
| static NodePtr | rebuild_node (const NodePtr &node, NodePtr left, NodePtr right) |
| |
| static NodePtr | insert_rec (const NodePtr &node, std::shared_ptr< const Key > key, std::shared_ptr< const T > value, const std::uint64_t priority, const Compare &cmp, bool &inserted) |
| |
| static NodePtr | insert_or_assign_rec (const NodePtr &node, std::shared_ptr< const Key > key, std::shared_ptr< const T > value, const std::uint64_t priority, const Compare &cmp, bool &inserted) |
| |
| static void | collect_items (const NodePtr &node, Array< std::pair< Key, T > > &out) |
| |
template<typename Key, typename
T, class Compare = Aleph::less<Key>>
class Aleph::PersistentTreapMap< Key, T, Compare >
Immutable ordered map backed by a path-copying treap.
- Template Parameters
-
| Key | Key type. |
| T | Mapped value type. |
| Compare | Strict weak ordering used for keys. Defaults to Aleph::less<Key>. |
Definition at line 546 of file tpl_persistent_treap.H.
template<typename Key , typename
T , class Compare = Aleph::less<Key>>
Return a new version without key.
- Parameters
-
- Returns
- New map version. If the key is absent, returns an unchanged version sharing the same root.
- Exceptions
-
| std::bad_alloc | or whatever Compare throws. |
Definition at line 794 of file tpl_persistent_treap.H.
References Aleph::PersistentTreapMap< Key, T, Compare >::cmp_, Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::erase_rec(), Aleph::PersistentTreapMap< Key, T, Compare >::next_priority_, Aleph::PersistentTreapMap< Key, T, Compare >::rebuild_node(), root(), and Aleph::PersistentTreapMap< Key, T, Compare >::root_.
Referenced by TEST(), and TEST().
template<typename Key , typename
T , class Compare = Aleph::less<Key>>
Find a mapped value.
- Parameters
-
- Returns
- Pointer to the stored mapped value, or
nullptr when absent. The pointer remains valid while this map version is alive.
- Exceptions
-
Definition at line 720 of file tpl_persistent_treap.H.
References Aleph::PersistentTreapMap< Key, T, Compare >::cmp_, Aleph::PersistentTreapMap< Key, T, Compare >::Node::key, Aleph::PersistentTreapMap< Key, T, Compare >::Node::left, Aleph::PersistentTreapMap< Key, T, Compare >::Node::right, Aleph::PersistentTreapMap< Key, T, Compare >::root_, and Aleph::PersistentTreapMap< Key, T, Compare >::Node::value.
Referenced by Aleph::PersistentTreapMap< Key, T, Compare >::contains(), main(), and TEST().
template<typename Key , typename
T , class Compare = Aleph::less<Key>>
template<typename KArg , typename VArg >
requires std::constructible_from<Key, KArg &&>
Return a new version with a binding inserted if absent.
- Template Parameters
-
| KArg | Type used to construct Key. |
| VArg | Type used to construct T. |
- Parameters
-
| key | Key to insert. |
| value | Mapped value to insert. |
- Returns
- New map version. If an equivalent key already exists, returns an unchanged version sharing the same root.
- Exceptions
-
| std::bad_alloc | or whatever construction/comparison throws. |
Definition at line 754 of file tpl_persistent_treap.H.
References Aleph::PersistentTreapMap< Key, T, Compare >::cmp_, Aleph::PersistentTreapMap< Key, T, Compare >::insert_rec(), Aleph::PersistentTreapMap< Key, T, Compare >::next_priority_, Aleph::detail::persistent_treap_priority(), root(), Aleph::PersistentTreapMap< Key, T, Compare >::root_, and value.
Referenced by main(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
template<typename Key , typename
T , class Compare = Aleph::less<Key>>
template<typename KArg , typename VArg >
requires std::constructible_from<Key, KArg &&>
Return a new version with key assigned to value.
- Template Parameters
-
| KArg | Type used to construct Key when the key is absent. |
| VArg | Type used to construct T. |
- Parameters
-
| key | Key to insert or update. |
| value | Mapped value for the returned version. |
- Returns
- New map version with the binding present.
- Exceptions
-
| std::bad_alloc | or whatever construction/comparison throws. |
Definition at line 775 of file tpl_persistent_treap.H.
References Aleph::PersistentTreapMap< Key, T, Compare >::cmp_, Aleph::PersistentTreapMap< Key, T, Compare >::insert_or_assign_rec(), Aleph::PersistentTreapMap< Key, T, Compare >::next_priority_, Aleph::detail::persistent_treap_priority(), root(), Aleph::PersistentTreapMap< Key, T, Compare >::root_, and value.
Referenced by main(), TEST(), TEST(), and TEST().
template<typename Key , typename
T , class Compare = Aleph::less<Key>>
Join two ordered, non-overlapping map versions.
- Parameters
-
| left | Map whose keys must all be less than every key in right. |
| right | Map whose keys must all be greater than every key in left. |
- Returns
- Joined map version.
- Exceptions
-
| std::domain_error | if right is not ordered under left's comparator, or if the key ranges overlap or touch. |
| std::bad_alloc | if node allocation fails. |
| Whatever | Compare throws. |
Definition at line 824 of file tpl_persistent_treap.H.
References ah_domain_error_unless, Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::can_join(), Aleph::PersistentTreapMap< Key, T, Compare >::cmp_, Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::is_valid_under(), Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::join_nodes(), Aleph::PersistentTreapMap< Key, T, Compare >::next_priority_, Aleph::PersistentTreapMap< Key, T, Compare >::rebuild_node(), and Aleph::PersistentTreapMap< Key, T, Compare >::root_.
Referenced by Aleph::PersistentTreapMap< Key, T, Compare >::join(), and TEST().
template<typename Key , typename
T , class Compare = Aleph::less<Key>>
Verify treap, BST and cached-size invariants.
- Returns
true if the internal structure is consistent.
- Exceptions
-
| Nothing | unless Compare throws. |
- Note
- Intended for tests and diagnostics; it is O(n).
Definition at line 879 of file tpl_persistent_treap.H.
References Aleph::and, Aleph::PersistentTreapMap< Key, T, Compare >::cmp_, Aleph::count(), Aleph::PersistentTreapMap< Key, T, Compare >::root_, Aleph::PersistentTreapMap< Key, T, Compare >::size(), and Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::verify_rec().
Referenced by TEST(), and TEST().