Yggdrasill
0.2
|
The Dynamic Segment Tree class. More...
#include <dynamic_segment_tree.hpp>
Public Types | |
using | KeyT = typename Node::KeyT |
using | ValueT = typename Node::ValueT |
using | AggValueT = typename Node::AggValueT |
using | MyClass = DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag > |
template<bool reverse> | |
using | const_iterator = typename InnerTree::template const_iterator< reverse > |
template<bool reverse> | |
using | iterator = typename InnerTree::template iterator< reverse > |
Public Member Functions | |
DynamicSegmentTree (MyClass &&other) | |
Move constructor. | |
DynamicSegmentTree () | |
Default constructor. | |
void | insert (Node &n) |
Insert an interval into the dynamic segment tree. More... | |
void | remove (Node &n) |
Removes an intervals from the dynamic segment tree. More... | |
bool | empty () const |
Returns whether the dynamic segment tree is empty. More... | |
AggValueT | query (const typename Node::KeyT &x) const noexcept |
Perform a stabbing query at point x. More... | |
template<class Combiner > | |
Combiner | get_combiner () const |
template<class Combiner > | |
Combiner | get_combiner (const typename Node::KeyT &lower, const typename Node::KeyT &upper, bool lower_closed=true, bool upper_closed=false) const |
template<class Combiner > | |
Combiner::ValueT | get_combined () const |
template<class Combiner > | |
Combiner::ValueT | get_combined (const typename Node::KeyT &lower, const typename Node::KeyT &upper, bool lower_closed=true, bool upper_closed=false) const |
const_iterator< false > | cbegin () const |
const_iterator< false > | cend () const |
const_iterator< false > | begin () const |
iterator< false > | begin () |
const_iterator< false > | end () const |
iterator< false > | end () |
const_iterator< true > | crbegin () const |
const_iterator< true > | crend () const |
const_iterator< true > | rbegin () const |
iterator< true > | rbegin () |
const_iterator< true > | rend () const |
iterator< true > | rend () |
const_iterator< false > | lower_bound_event (const typename Node::KeyT &key) const |
iterator< false > | lower_bound_event (const typename Node::KeyT &key) |
const_iterator< false > | upper_bound_event (const typename Node::KeyT &key) const |
iterator< false > | upper_bound_event (const typename Node::KeyT &key) |
void | clear () |
Removes all elements from the tree. More... | |
void | dbg_verify () const |
template<class Combiner > | |
void | dbg_verify_max_combiner () const |
void | dbg_print_inner_tree () const |
std::stringstream & | dbg_get_dot () const |
The Dynamic Segment Tree class.
This class provides a dynamic version of a segment tree. For details on the implementation, see DOCTODO. The dynamic segment tree provides the following operations:
where n is the number of intervals in the dynamic segment tree and A is the time it takes to aggregate a value, i.e., compute operator+(AggValueT, ValueT).
The DynamicSegmentTree can be based either on a red-black tree (the RBTree), or on a Zip Tree (the ZTree). By default, the red-black tree is used. However, especially for applications where segments are moved frequently, the Zip Tree has proven to be more efficient. You select the underlying tree via the TreeSelector template parameter.
DOCTODO combiners
Node | The node class in your tree, must be derived from DynSegTreeNodeBase |
NodeTraits | The node traits for your node class, must be derived from DynSegTreeNodeTraits |
Options | Options for this tree. See DOCTODO for details. |
TreeSelector | Specifies which balanced binary tree implementation to use for the underlying tree. Must be one of UseRBTree<...> (to use the red-black tree), UseZipTree<...> (to use the zip tree) or UseWBTree<...> (to use the weight-balanced tree). You need to specify the same selector at the DynSegTreeNodeBase! |
Tag | The tag of this tree. Allows to insert the same node in multiple dynamic segment trees. See DOCTODO for details. |
const_iterator<false> ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::begin | ( | ) | const |
Returns an iterator pointing to the smallest InnerNode representing a start or end event.
const_iterator<false> ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::cbegin | ( | ) | const |
Returns an iterator pointing to the smallest InnerNode representing a start or end event.
const_iterator<false> ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::cend | ( | ) | const |
Returns an iterator pointing after the largest InnerNode representing a start or end event.
void ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::clear | ( | ) |
Removes all elements from the tree.
TODO write a test for this method
Removes all elements from the tree.
const_iterator<true> ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::crbegin | ( | ) | const |
Returns an reverse iterator pointing to the largest InnerNode representing a start or end event.
const_iterator<true> ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::crend | ( | ) | const |
Returns an reverse iterator pointing before the smallest InnerNode representing a start or end event.
bool ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::empty | ( | ) | const |
Returns whether the dynamic segment tree is empty.
This method runs in O(1).
const_iterator<false> ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::end | ( | ) | const |
Returns an iterator pointing after the largest InnerNode representing a start or end event.
void ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::insert | ( | Node & | n | ) |
Insert an interval into the dynamic segment tree.
This inserts the interval represented by the node n into the dynamic segment tree. The interval may not be empty.
n | The node representing the interval being inserted |
const_iterator<false> ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::lower_bound_event | ( | const typename Node::KeyT & | key | ) | const |
Returns an iterator to the first event the key of which is not less than <key>
key | The key to search for. |
|
noexcept |
Perform a stabbing query at point x.
This query asks for the aggregate value over all intervals containing point x. This is a "stabbing query".
x | The point to query for |
const_iterator<true> ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::rbegin | ( | ) | const |
Returns an reverse iterator pointing to the largest InnerNode representing a start or end event.
void ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::remove | ( | Node & | n | ) |
Removes an intervals from the dynamic segment tree.
Removes the (previously inserted) node n from the dynamic segment tree
n | The node to be removed |
const_iterator<true> ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::rend | ( | ) | const |
Returns an reverse iterator pointing before the smallest InnerNode representing a start or end event.
const_iterator<false> ygg::DynamicSegmentTree< Node, NodeTraits, Combiners, Options, TreeSelector, Tag >::upper_bound_event | ( | const typename Node::KeyT & | key | ) | const |
Returns an iterator to the first event the key of which is greater than <key>
key | The key to search for. |