5 #include <initializer_list>
17 template<
typename _Key,
typename _Comp>
18 class vs_tree_strategy;
25 template<
typename _Key,
typename _Comp = std::less<_Key>>
53 height = (lh > rh ? lh : rh);
114 if (comp(_value, this->value))
142 template<
typename _Key,
typename _Comp = std::less<_Key>>
235 bool came_with_right = (
parents.top()->right ==
node ? true :
false);
265 template<
typename _Key,
typename _Comp = std::less<_Key>>
316 delete_subtree(node->left);
319 delete_subtree(node->right);
333 copy_subtree(this->head, _tree.head);
340 std::cout <<
"deleting " <<
this << std::endl;
342 delete_subtree(head);
389 if (node->
value == _x)
392 if (comp(_x, node->
value))
426 _height = head->
height + 1;
452 template<
typename _Key,
typename _Comp = std::less<_Key>,
typename _Strategy = vs_tree_strategy<_Key, _Comp>>
457 "Provided invalid strategy class in template");
490 const _Comp& __comp = _Comp())
508 : _v_t(__vs_tree._v_t.Get()) { }
525 {
return _v_t.
Get().begin(); }
535 {
return _v_t.
Get().end(); }
542 {
return _v_t.
Get().size(); }
549 {
return _v_t.
Get().height(); }
556 {
return _v_t.
Get().find(__x); }
582 template<
typename _Key,
typename _Comp>
592 auto found = dst.
find(i);
593 if (found != dst.
end())
594 merge_same_element(dst, *found, i);
608 template<
typename _Key,
typename _Comp>
612 std::ostringstream o;
614 for (
auto& i: temp) {
Wrapper to make any class Versioned.
const T & Get() const
Get the current value of the object in the current Revision.
bool Set(const T &v, const std::function< bool(T &)> &updater=nullptr)
Set new value of the object.
serves as stl-like interface from node to vs_tree; handles allocations in construction and destructio...
_vs_tree(const _vs_tree &_tree)
_vs_tree_node< _Key, _Comp >::_Ptr_type _Ptr_type
_vs_tree_node< _Key, _Comp >::size_type size_type
_vs_tree_iterator< _Key, _Comp > iterator
void push(const _Key &_value)
iterator find_subtree(const _Key &_x, const _Ptr_type &node, _Comp comp=_Comp{}) const
iterator find(const _Key &_x) const
simple recursive implementation of find
simpliest determenistic merge strategy.
void merge_same_element(_vs_tree< _Key, _Comp > &dst, _Key &dstk, _Key &srck)
void merge(_vs_tree< _Key, _Comp > &dst, _vs_tree< _Key, _Comp > &src)
A versioned AVL-tree with deep copy constructor in internal classes.
vs_tree(std::initializer_list< _Key > __l, const _Comp &__comp=_Comp())
Builds a vs_tree from an initializer_list.
iterator end() const
end constant iterator
_vs_tree< _Key, _Comp >::iterator iterator
Versioned< _vs_tree< _Key, _Comp >, _Strategy > _Versioned
void push(const _Key &__x)
Attempts to insert an element into the vs_tree.
iterator find(const _Key &__x) const
find element in tree
size_type size() const noexcept
size of underlying tree
_vs_tree< _Key, _Comp >::size_type size_type
size_type height() const noexcept
height of underlying tree
iterator begin() const
begin constant iterator
vs_tree(const vs_tree &__vs_tree)
vs_tree copy constructor
vs_tree(const _Comp &__comp=_Comp())
Creates a vs_tree with no elements.
std::ostream & operator<<(std::ostream &os, vs_tree< _Key, _Comp > const &value)
concept IsMergeStrategy
Concept for compile-time type checking passed user strategies.
Implementation of the class Revision.
friend bool operator!=(const _Self &__x, const _Self &__y)
_vs_tree_iterator(_Ptr_type __x)
_vs_tree_iterator< _Key, _Comp > _Self
_vs_tree_node< _Key, _Comp >::_Ptr_type _Ptr_type
std::forward_iterator_tag iterator_category
ptrdiff_t difference_type
friend bool operator==(const _Self &__x, const _Self &__y)
std::stack< _Ptr_type > parents
Manages all balancing logic and correlating allocations;.
void refresh_node_height()
_Ptr_type node_insert(const _Key &_value, _Comp comp=_Comp{})
Fall down recursively, insert and rebalance on the way up.
size_type node_delta_height()
_vs_tree_node(const _vs_tree_node &_node)
_vs_tree_node< _Key, _Comp > * _Ptr_type
_vs_tree_node(const _Key &_value)
Implementation of the Versioned classes and interface.