|
Flow
Documentation for the Flow C++ Library
|
A standard segment tree that supports O(log n) for point update and range query. The binary operation must be commutative. More...
#include <flow_segment_tree.h>
Public Types | |
| using | value_type = T |
| using | reference = T& |
| using | const_reference = const T& |
| using | pointer = T* |
| using | const_pointer = const T* |
| using | iterator = T* |
| using | const_iterator = const T* |
| using | difference_type = std::ptrdiff_t |
| using | container_type = Vector<T, Allocator> |
| using | allocator_type = container_type::allocator_type |
Public Member Functions | |
| constexpr | SegmentTree () noexcept(noexcept(container_type()) &&noexcept(BinOp())) |
| constexpr | SegmentTree (const allocator_type &allocator) noexcept(noexcept(container_type(allocator)) &&noexcept(BinOp())) |
| constexpr | SegmentTree (const SegmentTree &)=default |
| constexpr | SegmentTree (const SegmentTree &rhs, const allocator_type &allocator) |
| constexpr | SegmentTree (SegmentTree &&)=default |
| constexpr | SegmentTree (SegmentTree &&rhs, const allocator_type &allocator) noexcept(noexcept(container_type(std::move(rhs.data_), allocator)) &&noexcept(BinOp(std::move(rhs.binOp_)))) |
| template<std::forward_iterator It> | |
| constexpr | SegmentTree (It first, It last, BinOp binOp={}, const allocator_type &allocator={}) |
| Iterator range constructor. | |
| constexpr | SegmentTree (std::initializer_list< T > list, BinOp binOp={}, const allocator_type &allocator={}) |
| Initializer list constructor. | |
| ~SegmentTree ()=default | |
| allocator_type | get_allocator () const noexcept |
| constexpr std::size_t | size () const |
| Return the number of input elements. This only counts the leaf node from the input. | |
| constexpr bool | empty () const |
| Check if the segmeent tree is empty. | |
| constexpr void | setPoint (std::size_t i, const T &value) |
| Set the new value at index i, then update the tree structure. | |
| constexpr std::optional< T > | getRange (std::size_t first, std::size_t last) const |
| Query the value from [first, last) after applying the binary operator adjacent-pair wise. If the range is empty, return std::nullopt. | |
Private Member Functions | |
| constexpr void | buildParent () |
Static Private Member Functions | |
| static constexpr bool | hasParent (std::size_t i) noexcept |
| static constexpr std::size_t | getParent (std::size_t i) noexcept |
| static constexpr std::size_t | getLeftChild (std::size_t i) noexcept |
| static constexpr std::size_t | getSibling (std::size_t i) noexcept |
| static constexpr bool | isLeftChild (std::size_t i) noexcept |
| static constexpr bool | isRightChild (std::size_t i) noexcept |
Private Attributes | |
| container_type | data_ |
| BinOp | binOp_ |
A standard segment tree that supports O(log n) for point update and range query. The binary operation must be commutative.
| T | |
| Allocator | |
| BinOp |
Definition at line 14 of file flow_segment_tree.h.
| using flow::SegmentTree< T, BinOp, Allocator >::allocator_type = container_type::allocator_type |
Definition at line 25 of file flow_segment_tree.h.
| using flow::SegmentTree< T, BinOp, Allocator >::const_iterator = const T* |
Definition at line 22 of file flow_segment_tree.h.
| using flow::SegmentTree< T, BinOp, Allocator >::const_pointer = const T* |
Definition at line 20 of file flow_segment_tree.h.
| using flow::SegmentTree< T, BinOp, Allocator >::const_reference = const T& |
Definition at line 18 of file flow_segment_tree.h.
| using flow::SegmentTree< T, BinOp, Allocator >::container_type = Vector<T, Allocator> |
Definition at line 24 of file flow_segment_tree.h.
| using flow::SegmentTree< T, BinOp, Allocator >::difference_type = std::ptrdiff_t |
Definition at line 23 of file flow_segment_tree.h.
| using flow::SegmentTree< T, BinOp, Allocator >::iterator = T* |
Definition at line 21 of file flow_segment_tree.h.
| using flow::SegmentTree< T, BinOp, Allocator >::pointer = T* |
Definition at line 19 of file flow_segment_tree.h.
| using flow::SegmentTree< T, BinOp, Allocator >::reference = T& |
Definition at line 17 of file flow_segment_tree.h.
| using flow::SegmentTree< T, BinOp, Allocator >::value_type = T |
Definition at line 16 of file flow_segment_tree.h.
|
inlineconstexprnoexcept |
Definition at line 32 of file flow_segment_tree.h.
Referenced by SegmentTree(), SegmentTree(), SegmentTree(), and SegmentTree().
|
inlineexplicitconstexprnoexcept |
Definition at line 37 of file flow_segment_tree.h.
|
constexprdefault |
References SegmentTree().
|
inlineconstexpr |
|
constexprdefault |
References SegmentTree().
|
inlineconstexprnoexcept |
|
inlineexplicitconstexpr |
Iterator range constructor.
| first | Iterator to first element. |
| last | Iterator to one-past-last element. |
| binOp | Binary operator. |
| alloc | Allocator. |
Definition at line 59 of file flow_segment_tree.h.
|
inlineexplicitconstexpr |
Initializer list constructor.
| list | Initializer list. |
| binOp | Binary operator. |
| alloc | Allocator. |
Definition at line 69 of file flow_segment_tree.h.
|
default |
|
inlineconstexprprivate |
Definition at line 147 of file flow_segment_tree.h.
References binOp_, data_, getLeftChild(), and size().
|
inlineconstexpr |
Check if the segmeent tree is empty.
Definition at line 90 of file flow_segment_tree.h.
References data_.
|
inlinenoexcept |
Definition at line 76 of file flow_segment_tree.h.
References data_.
|
inlinestaticconstexprprivatenoexcept |
Definition at line 164 of file flow_segment_tree.h.
Referenced by buildParent().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 159 of file flow_segment_tree.h.
References hasParent().
Referenced by getRange(), and setPoint().
|
inlineconstexpr |
Query the value from [first, last) after applying the binary operator adjacent-pair wise. If the range is empty, return std::nullopt.
| first | The begin index. |
| last | The end index. |
Definition at line 113 of file flow_segment_tree.h.
References binOp_, data_, getParent(), isRightChild(), and size().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 168 of file flow_segment_tree.h.
Referenced by setPoint().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 155 of file flow_segment_tree.h.
Referenced by getParent(), and setPoint().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 172 of file flow_segment_tree.h.
Referenced by isRightChild().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 176 of file flow_segment_tree.h.
References isLeftChild().
Referenced by getRange().
|
inlineconstexpr |
Set the new value at index i, then update the tree structure.
| i | The index. |
| value | New value. |
Definition at line 97 of file flow_segment_tree.h.
References binOp_, data_, getParent(), getSibling(), hasParent(), and size().
|
inlineconstexpr |
Return the number of input elements. This only counts the leaf node from the input.
Definition at line 84 of file flow_segment_tree.h.
References data_.
Referenced by buildParent(), getRange(), and setPoint().
|
private |
Definition at line 29 of file flow_segment_tree.h.
Referenced by buildParent(), getRange(), SegmentTree(), SegmentTree(), SegmentTree(), SegmentTree(), and setPoint().
|
private |
Definition at line 28 of file flow_segment_tree.h.
Referenced by buildParent(), empty(), get_allocator(), getRange(), SegmentTree(), SegmentTree(), SegmentTree(), SegmentTree(), setPoint(), and size().