|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Immutable ordered set backed by a path-copying treap. More...
#include <tpl_persistent_treap.H>
Classes | |
| struct | Node |
Public Member Functions | |
| PersistentTreapSet (Compare cmp=Compare()) | |
| Construct an empty persistent set. | |
| bool | is_empty () const noexcept |
| Return true when the set has no keys. | |
| size_t | size () const noexcept |
| Return the number of keys stored in this version. | |
| const Key * | find (const Key &key) const |
Find a key equivalent to key. | |
| bool | contains (const Key &key) const |
Test whether key is present. | |
| PersistentTreapSet | insert (const Key &key) const |
Return a new version with key inserted by copy. | |
| PersistentTreapSet | insert (Key &&key) const |
Return a new version with key inserted by move. | |
| PersistentTreapSet | erase (const Key &key) const |
Return a new version without key. | |
| std::pair< PersistentTreapSet, PersistentTreapSet > | split (const Key &pivot) const |
Split this version around pivot. | |
| PersistentTreapSet | join (const PersistentTreapSet &right) const |
Join this version with right. | |
| Array< Key > | keys () const |
| Return all keys in sorted order. | |
| bool | verify () const |
| Verify treap, BST and cached-size invariants. | |
Static Public Member Functions | |
| static PersistentTreapSet | join (const PersistentTreapSet &left, const PersistentTreapSet &right) |
| Join two ordered, non-overlapping set versions. | |
Private Types | |
| using | NodePtr = std::shared_ptr< const Node > |
| using | NodeOps = detail::PersistentTreapNodeOps< Node, Key, Compare > |
Private Member Functions | |
| PersistentTreapSet (NodePtr root, Compare cmp, const std::uint64_t next_priority) | |
Static Private Member Functions | |
| static NodePtr | make_node (std::shared_ptr< const Key > key, 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, const std::uint64_t priority, const Compare &cmp, bool &inserted) |
Private Attributes | |
| NodePtr | root_ |
| Compare | cmp_ |
| std::uint64_t | next_priority_ = 0 |
Immutable ordered set backed by a path-copying treap.
| Key | Key type stored by the set. |
| Compare | Strict weak ordering used for keys. Defaults to Aleph::less<Key>. |
Definition at line 282 of file tpl_persistent_treap.H.
|
private |
Definition at line 294 of file tpl_persistent_treap.H.
|
private |
Definition at line 293 of file tpl_persistent_treap.H.
|
inlineprivate |
Definition at line 363 of file tpl_persistent_treap.H.
|
inlineexplicit |
Construct an empty persistent set.
| cmp | Comparator used for key ordering. |
| Nothing | unless copying cmp throws. |
Definition at line 374 of file tpl_persistent_treap.H.
|
inline |
Test whether key is present.
| key | Key to search. |
true if an equivalent key is stored. | Whatever | Compare throws. |
Definition at line 416 of file tpl_persistent_treap.H.
References Aleph::PersistentTreapSet< Key, Compare >::find().
|
inline |
Return a new version without key.
| key | Key to erase. |
| std::bad_alloc | or whatever Compare throws. |
Definition at line 459 of file tpl_persistent_treap.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::PersistentTreapSet< Key, Compare >::cmp_, Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::erase_rec(), Aleph::PersistentTreapSet< Key, Compare >::next_priority_, Aleph::PersistentTreapSet< Key, Compare >::rebuild_node(), root(), and Aleph::PersistentTreapSet< Key, Compare >::root_.
|
inline |
Find a key equivalent to key.
| key | Key to search. |
nullptr when absent. The pointer remains valid while this set version is alive. | Whatever | Compare throws. |
Definition at line 398 of file tpl_persistent_treap.H.
References Aleph::PersistentTreapSet< Key, Compare >::cmp_, Aleph::PersistentTreapSet< Key, Compare >::Node::key, Aleph::PersistentTreapSet< Key, Compare >::Node::left, Aleph::PersistentTreapSet< Key, Compare >::Node::right, and Aleph::PersistentTreapSet< Key, Compare >::root_.
Referenced by Aleph::PersistentTreapSet< Key, Compare >::contains().
|
inline |
Return a new version with key inserted by copy.
| key | Key to insert. |
| std::bad_alloc | or whatever Compare/Key copy construction throws. |
Definition at line 427 of file tpl_persistent_treap.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::PersistentTreapSet< Key, Compare >::cmp_, Aleph::PersistentTreapSet< Key, Compare >::insert_rec(), Aleph::PersistentTreapSet< Key, Compare >::next_priority_, Aleph::detail::persistent_treap_priority(), root(), and Aleph::PersistentTreapSet< Key, Compare >::root_.
Referenced by main(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inline |
Return a new version with key inserted by move.
| key | Key to move into the new version. |
| std::bad_alloc | or whatever Compare/Key move construction throws. |
Definition at line 443 of file tpl_persistent_treap.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::PersistentTreapSet< Key, Compare >::cmp_, Aleph::PersistentTreapSet< Key, Compare >::insert_rec(), Aleph::PersistentTreapSet< Key, Compare >::next_priority_, Aleph::detail::persistent_treap_priority(), root(), and Aleph::PersistentTreapSet< Key, Compare >::root_.
|
inlinestaticprivate |
Definition at line 327 of file tpl_persistent_treap.H.
References Aleph::blossom_maximum_cardinality_matching(), cmp(), Aleph::PersistentTreapSet< Key, Compare >::insert_rec(), Aleph::PersistentTreapSet< Key, Compare >::make_node(), Aleph::PersistentTreapSet< Key, Compare >::rebuild_node(), Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::rotate_left(), and Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::rotate_right().
Referenced by Aleph::PersistentTreapSet< Key, Compare >::insert(), Aleph::PersistentTreapSet< Key, Compare >::insert(), and Aleph::PersistentTreapSet< Key, Compare >::insert_rec().
|
inlinenoexcept |
Return true when the set has no keys.
true iff size() == 0. | Nothing. |
Definition at line 384 of file tpl_persistent_treap.H.
References Aleph::PersistentTreapSet< Key, Compare >::root_.
Referenced by TEST().
|
inlinestatic |
Join two ordered, non-overlapping set versions.
| left | Set whose keys must all be less than every key in right. |
| right | Set whose keys must all be greater than every key in left. |
| 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 489 of file tpl_persistent_treap.H.
References ah_domain_error_unless, Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::can_join(), Aleph::PersistentTreapSet< Key, Compare >::cmp_, Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::is_valid_under(), Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::join_nodes(), Aleph::PersistentTreapSet< Key, Compare >::next_priority_, Aleph::PersistentTreapSet< Key, Compare >::rebuild_node(), and Aleph::PersistentTreapSet< Key, Compare >::root_.
Referenced by Aleph::PersistentTreapSet< Key, Compare >::join().
|
inline |
Join this version with right.
| right | Set whose keys must all be greater than every key in this set. |
| std::domain_error | if right is not ordered under this set's comparator, or if the key ranges overlap or touch. |
| std::bad_alloc | if node allocation fails. |
| Whatever | Compare throws. |
Definition at line 508 of file tpl_persistent_treap.H.
References Aleph::PersistentTreapSet< Key, Compare >::join().
|
inline |
Return all keys in sorted order.
| std::bad_alloc | or whatever copying Key throws. |
Definition at line 517 of file tpl_persistent_treap.H.
References Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::collect_keys(), out, Aleph::Array< T >::reserve(), Aleph::PersistentTreapSet< Key, Compare >::root_, and Aleph::PersistentTreapSet< Key, Compare >::size().
Referenced by TEST().
|
inlinestaticprivate |
Definition at line 300 of file tpl_persistent_treap.H.
References ah_overflow_error_if, Aleph::blossom_maximum_cardinality_matching(), and Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::node_size().
Referenced by Aleph::PersistentTreapSet< Key, Compare >::insert_rec(), and Aleph::PersistentTreapSet< Key, Compare >::rebuild_node().
|
inlinestaticprivate |
Definition at line 322 of file tpl_persistent_treap.H.
References Aleph::PersistentTreapSet< Key, Compare >::make_node().
Referenced by Aleph::PersistentTreapSet< Key, Compare >::erase(), Aleph::PersistentTreapSet< Key, Compare >::insert_rec(), Aleph::PersistentTreapSet< Key, Compare >::join(), and Aleph::PersistentTreapSet< Key, Compare >::split().
|
inlinenoexcept |
Return the number of keys stored in this version.
| Nothing. |
Definition at line 390 of file tpl_persistent_treap.H.
References Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::node_size(), and Aleph::PersistentTreapSet< Key, Compare >::root_.
Referenced by Aleph::PersistentTreapSet< Key, Compare >::keys(), and Aleph::PersistentTreapSet< Key, Compare >::verify().
|
inline |
Split this version around pivot.
| pivot | Split key. |
{less, greater_equal} where the first set contains keys strictly less than pivot and the second contains the rest. | std::bad_alloc | or whatever Compare throws. |
Definition at line 473 of file tpl_persistent_treap.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::PersistentTreapSet< Key, Compare >::cmp_, Aleph::PersistentTreapSet< Key, Compare >::next_priority_, Aleph::PersistentTreapSet< Key, Compare >::rebuild_node(), Aleph::PersistentTreapSet< Key, Compare >::root_, and Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::split_rec().
Referenced by TEST().
|
inline |
Verify treap, BST and cached-size invariants.
true if the internal structure is consistent. | Nothing | unless Compare throws. |
Definition at line 531 of file tpl_persistent_treap.H.
References Aleph::and, Aleph::PersistentTreapSet< Key, Compare >::cmp_, Aleph::count(), Aleph::PersistentTreapSet< Key, Compare >::root_, Aleph::PersistentTreapSet< Key, Compare >::size(), and Aleph::detail::PersistentTreapNodeOps< Node, Key, Compare >::verify_rec().
|
private |
Definition at line 297 of file tpl_persistent_treap.H.
Referenced by Aleph::PersistentTreapSet< Key, Compare >::erase(), Aleph::PersistentTreapSet< Key, Compare >::find(), Aleph::PersistentTreapSet< Key, Compare >::insert(), Aleph::PersistentTreapSet< Key, Compare >::insert(), Aleph::PersistentTreapSet< Key, Compare >::join(), Aleph::PersistentTreapSet< Key, Compare >::split(), and Aleph::PersistentTreapSet< Key, Compare >::verify().
|
private |
Definition at line 298 of file tpl_persistent_treap.H.
Referenced by Aleph::PersistentTreapSet< Key, Compare >::erase(), Aleph::PersistentTreapSet< Key, Compare >::insert(), Aleph::PersistentTreapSet< Key, Compare >::insert(), Aleph::PersistentTreapSet< Key, Compare >::join(), and Aleph::PersistentTreapSet< Key, Compare >::split().
|
private |
Definition at line 296 of file tpl_persistent_treap.H.
Referenced by Aleph::PersistentTreapSet< Key, Compare >::erase(), Aleph::PersistentTreapSet< Key, Compare >::find(), Aleph::PersistentTreapSet< Key, Compare >::insert(), Aleph::PersistentTreapSet< Key, Compare >::insert(), Aleph::PersistentTreapSet< Key, Compare >::is_empty(), Aleph::PersistentTreapSet< Key, Compare >::join(), Aleph::PersistentTreapSet< Key, Compare >::keys(), Aleph::PersistentTreapSet< Key, Compare >::size(), Aleph::PersistentTreapSet< Key, Compare >::split(), and Aleph::PersistentTreapSet< Key, Compare >::verify().