30template <
class TItem,
class TAlloc,
class TVersion>
93template <
class TKey,
class TItem,
class TKeyComp,
class TAlloc>
96 TKey, TItem, TKeyComp, TAlloc,
97 persistent_avl_node<TItem, TAlloc, persistent_avl_version_type>> {
117 using path_type = std::vector<std::pair<node_ptr, bool>>;
120 std::vector<node_ptr> roots;
123 std::vector<size_type> node_counts;
129 std::vector<version_type> based_on;
152 template <std::invocable TCallback>
163 path_type copy_path(
const path_type &path,
node_ptr new_child,
166 bool is_valid_version(
version_type version)
const noexcept {
167 return 0 < version ||
static_cast<size_t>(version) <= roots.size();
174 int parent_index,
const path_type &parents);
180 bool child_is_right,
int parent_index,
181 const path_type &parents);
222 if (!is_valid_version(version)) {
225 return roots[version];
237 [[nodiscard]] std::vector<node_ptr>
299 template <std::invocable TCallback>
327 if (!is_valid_version(version)) {
330 return node_counts[version];
352 return based_on[version];
Header for functions and classes common to all avl trees.
Implementation of the persistent AVL tree.
Base class for avl trees.
Definition _avl_common.hpp:76
TKey key_type
Definition _avl_common.hpp:78
avl_node_ptr< node_type, allocator_type > node_ptr
The node pointer type.
Definition _avl_common.hpp:90
TKeyComp comparator_type
Definition _avl_common.hpp:80
TAlloc allocator_type
Definition _avl_common.hpp:81
comparator_type comparator
Definition _avl_common.hpp:105
node_alloc_type allocator
Definition _avl_common.hpp:106
typename node_alloc_traits::size_type size_type
The size type.
Definition _avl_common.hpp:100
Persitent AVL tree implementation.
Definition _persistent_avl.hpp:97
persistent_avl_tree & operator=(const persistent_avl_tree &other)
Copies another tree.
Definition _persistent_avl.ipp:37
version_type get_current_version() const noexcept
Returns the current verison.
Definition _persistent_avl.hpp:345
node_ptr get_root(version_type version) const noexcept
Returns the trees root in a given version.
Definition _persistent_avl.hpp:221
std::pair< node_ptr, bool > insert(const key_type &key, TCallback &&callback, version_type version, bool do_assign)
Inserts an item to the tree.
node_ptr find(const key_type &key, version_type version) const noexcept
Finds a node with the given key in the given version, if there isn't any returns a nullptr.
Definition _persistent_avl.ipp:291
typename base::size_type size_type
Definition _persistent_avl.hpp:109
persistent_avl_version_type version_type
Definition _persistent_avl.hpp:99
std::pair< bool, version_type > erase(const key_type &key, version_type version) noexcept
Erases the node with the given key or does nothing if the key does not exist.
Definition _persistent_avl.ipp:510
void clear_all() noexcept
Erases the whole tree across versions.
Definition _persistent_avl.ipp:319
int get_height(version_type version) const
Returns the height of the tree in the given version.
Definition _persistent_avl.ipp:709
~persistent_avl_tree() noexcept
Destroys the tree.
Definition _persistent_avl.ipp:73
base::size_type size(version_type version) const noexcept
Returns the current number of nodes in the given version.
Definition _persistent_avl.hpp:326
typename base::node_ptr node_ptr
Definition _persistent_avl.hpp:107
version_type get_preceding_version(version_type version) const
Returns the preceding version to the given version.
Definition _persistent_avl.hpp:351
typename base::key_type key_type
Definition _persistent_avl.hpp:108
std::vector< node_ptr > list_in_order(version_type version) const noexcept
Returns a vector of nodes sorted by keys.
Definition _persistent_avl.ipp:262
int persistent_avl_version_type
The version type.
Definition _persistent_avl.hpp:51
int8_t avl_sign_type
The type to use for the trinary sign value for each node.
Definition _avl_common.hpp:50
std::allocator_traits< avl_node_allocator_type< TNode, TAlloc > >::pointer avl_node_ptr
A node pointer type.
Definition _avl_common.hpp:72
Declarations of the persistent map.
Definition _avl.hpp:14
Persistent AVL Tree Node.
Definition _persistent_avl.hpp:31
TItem item
The key / key, value pair.
Definition _persistent_avl.hpp:33
avl_node_ptr< persistent_avl_node, TAlloc > right
The right sub-tree.
Definition _persistent_avl.hpp:44
avl_sign_type sign
Determines whether the node is leaning to one side or balanced.
Definition _persistent_avl.hpp:38
TVersion version
The version which the node was created in.
Definition _persistent_avl.hpp:47
avl_node_ptr< persistent_avl_node, TAlloc > left
The left sub-tree.
Definition _persistent_avl.hpp:41