API Reference¶
-
template<typename Key, typename Value>
class flat_segment_tree¶ Public Types
-
typedef size_t size_type¶
-
using node = st::detail::node<key_type, leaf_value_type>¶
-
using nonleaf_node = st::detail::nonleaf_node<key_type, nonleaf_value_type>¶
-
using const_segment_iterator = mdds::fst::detail::const_segment_iterator<flat_segment_tree>¶
Public Functions
-
inline const_iterator begin() const¶
Return an iterator that points to the first leaf node that corresponds with the start position of the first segment.
- Returns:
immutable iterator that points to the first leaf node that corresponds with the start position of the first segment.
-
inline const_iterator end() const¶
Return an iterator that points to the position past the last leaf node that corresponds with the end position of the last segment.
- Returns:
immutable iterator that points to the position past last leaf node that corresponds with the end position of the last segment.
-
inline const_reverse_iterator rbegin() const¶
Return an iterator that points to the last leaf node that corresponds with the end position of the last segment. This iterator moves in the reverse direction of a normal iterator.
- Returns:
immutable reverse iterator that points to the last leaf node that corresponds with the end position of the last segment.
-
inline const_reverse_iterator rend() const¶
Return an iterator that points to the position past the first leaf node that corresponds with the start position of the first segment. This iterator moves in the reverse direction of a normal iterator.
- Returns:
immutable reverse iterator that points to the position past first leaf node that corresponds with the start position of the first segment.
-
const_segment_iterator begin_segment() const¶
Return an immutable iterator that points to the first segment stored in the tree. It iterates through the segments one segment at a time. Each iterator value consists of
start,end, andvaluemembers that correspond with the start and end positions of a segment and the value of that segment, respectively.- Returns:
immutable iterator that points to the first segment stored in the tree.
-
const_segment_iterator end_segment() const¶
Return an immutable iterator that points to the position past the last segment stored in the tree. It iterates through the segments one segment at a time. Each iterator value consists of
start,end, andvaluemembers that correspond with the start and end positions of a segment and the value of that segment, respectively.- Returns:
immutable iterator that points to the position past the last segment stored in the tree.
-
const_segment_range_type segment_range() const¶
Return a range object that provides a begin iterator and an end sentinel.
-
flat_segment_tree() = delete¶
-
flat_segment_tree(key_type min_val, key_type max_val, value_type init_val)¶
Constructor that takes minimum and maximum keys and the value to be used for the initial segment.
- Parameters:
min_val – minimum allowed key value for the entire series of segments.
max_val – maximum allowed key value for the entires series of segments.
init_val – value to be used for the initial segment. This value will also be used for empty segments.
-
flat_segment_tree(const flat_segment_tree &r)¶
Copy constructor only copies the leaf nodes.
-
flat_segment_tree(flat_segment_tree &&other) noexcept(nothrow_move_constructible_v)¶
Move constructor.
Warning
The source instance will not be usable after the move construction.
-
~flat_segment_tree()¶
-
flat_segment_tree<Key, Value> &operator=(const flat_segment_tree &other)¶
Copy assignment operator.
Note
It only copies the leaf nodes.
- Parameters:
other – Source instance to copy from.
-
flat_segment_tree<Key, Value> &operator=(flat_segment_tree &&other) noexcept(nothrow_move_assignable_v)¶
Move assignment operator.
- Parameters:
other – Source instance to move from.
-
void swap(flat_segment_tree &other) noexcept(nothrow_swappable_v)¶
Swap the content of the tree with another instance.
- Parameters:
other – instance of flat_segment_tree to swap content with.
-
void clear()¶
Remove all stored segments except for the initial segment. The minimum and maximum keys and the default value will be retained after the call returns. This call will also remove the tree.
-
inline std::pair<const_iterator, bool> insert_front(key_type start_key, key_type end_key, value_type val)¶
Insert a new segment into the tree. It searches for the point of insertion from the first leaf node.
- Parameters:
start_key – start value of the segment being inserted. The value is inclusive.
end_key – end value of the segment being inserted. The value is not inclusive.
val – value associated with this segment.
- Returns:
pair of const_iterator corresponding to the start position of the inserted segment, and a boolean value indicating whether or not the insertion has modified the tree.
-
inline std::pair<const_iterator, bool> insert_back(key_type start_key, key_type end_key, value_type val)¶
Insert a new segment into the tree. Unlike the insert_front() counterpart, this method searches for the point of insertion from the last leaf node toward the first.
- Parameters:
start_key – start value of the segment being inserted. The value is inclusive.
end_key – end value of the segment being inserted. The value is not inclusive.
val – value associated with this segment.
- Returns:
pair of const_iterator corresponding to the start position of the inserted segment, and a boolean value indicating whether or not the insertion has modified the tree.
-
std::pair<const_iterator, bool> insert(const_iterator pos, key_type start_key, key_type end_key, value_type val)¶
Insert a new segment into the tree at or after specified point of insertion.
- Parameters:
pos – specified insertion point
start_key – start value of the segment being inserted. The value is inclusive.
end_key – end value of the segment being inserted. The value is not inclusive.
val – value associated with this segment.
- Returns:
pair of const_iterator corresponding to the start position of the inserted segment, and a boolean value indicating whether or not the insertion has modified the tree.
-
void shift_left(key_type start_key, key_type end_key)¶
Remove a segment specified by the start and end key values, and shift the remaining segments (i.e. those segments that come after the removed segment) to left. Note that the start and end positions of the segment being removed must be within the base segment span.
- Parameters:
start_key – start position of the segment being removed.
end_key – end position of the segment being removed.
-
void shift_right(key_type pos, key_type size, bool skip_start_node)¶
Shift all segments that occur at or after the specified start position to right by the size specified.
- Parameters:
pos – position where the right-shift occurs.
size – amount of shift (must be greater than 0)
skip_start_node – if true, and the specified position is at an existing node position, that node will not be shifted. This argument has no effect if the position specified does not coincide with any of the existing nodes.
-
std::pair<const_iterator, bool> search(key_type key, value_type &value, key_type *start_key = nullptr, key_type *end_key = nullptr) const¶
Perform leaf-node search for a value associated with a key.
- Parameters:
key – key value
value – value associated with key specified gets stored upon successful search.
start_key – pointer to a variable where the start key value of the segment that contains the key gets stored upon successful search.
end_key – pointer to a variable where the end key value of the segment that contains the key gets stored upon successful search.
- Returns:
a pair of const_iterator corresponding to the start position of the segment containing the key, and a boolean value indicating whether or not the search has been successful.
-
std::pair<const_iterator, bool> search(const_iterator pos, key_type key, value_type &value, key_type *start_key = nullptr, key_type *end_key = nullptr) const¶
Perform leaf-node search for a value associated with a key.
- Parameters:
pos – position from which the search should start. When the position is invalid, it falls back to the normal search.
key – key value.
value – value associated with key specified gets stored upon successful search.
start_key – pointer to a variable where the start key value of the segment that contains the key gets stored upon successful search.
end_key – pointer to a variable where the end key value of the segment that contains the key gets stored upon successful search.
- Returns:
a pair of const_iterator corresponding to the start position of the segment containing the key, and a boolean value indicating whether or not the search has been successful.
-
const_iterator search(key_type key) const¶
Perform leaf-node search for a value associated with a key.
- Parameters:
key – Key value to perform search for.
- Returns:
Iterator position associated with the start position of the segment containing the key, or end iterator position upon search failure.
-
const_iterator search(const_iterator pos, key_type key) const¶
Perform leaf-node search for a value associated with a key.
- Parameters:
pos – Position from which the search should start if valid. In case of an invalid position, it falls back to a search starting with the first position.
key – Key value to perform search for.
- Returns:
Iterator position associated with the start position of the segment containing the key, or end iterator position if the search has failed.
-
std::pair<const_iterator, bool> search_tree(key_type key, value_type &value, key_type *start_key = nullptr, key_type *end_key = nullptr) const¶
Perform tree search for a value associated with a key. This method assumes that the tree is valid. Call is_tree_valid() to find out whether the tree is valid, and build_tree() to build a new tree in case it’s not.
- Parameters:
key – key value
value – value associated with key specified gets stored upon successful search.
start_key – pointer to a variable where the start key value of the segment that contains the key gets stored upon successful search.
end_key – pointer to a variable where the end key value of the segment that contains the key gets stored upon successful search.
- Returns:
a pair of const_iterator corresponding to the start position of the segment containing the key, and a boolean value indicating whether or not the search has been successful.
-
const_iterator search_tree(key_type key) const¶
Perform tree search for a value associated with a key. The tree must be valid before performing the search, else the search will fail.
- Parameters:
key – Key value to perform search for.
- Returns:
Iterator position associated with the start position of the segment containing the key, or end iterator position if the search has failed.
-
void build_tree()¶
Build a tree of non-leaf nodes based on the values stored in the leaf nodes. The tree must be valid before you can call the search_tree() method.
-
inline bool valid_tree() const noexcept¶
- Returns:
true if the tree is valid, otherwise false. The tree must be valid before you can call the search_tree() method.
-
inline bool is_tree_valid() const noexcept¶
- Deprecated:
Use valid_tree() instead.
- Returns:
true if the tree is valid, otherwise false. The tree must be valid before you can call the search_tree() method.
-
bool operator==(const flat_segment_tree &other) const noexcept(nothrow_eq_comparable_v)¶
Equality between two flat_segment_tree instances is evaluated by comparing the keys and the values of the leaf nodes only. Neither the non-leaf nodes nor the validity of the tree is evaluated.
-
inline bool operator!=(const flat_segment_tree &other) const noexcept(nothrow_eq_comparable_v)¶
-
inline const value_type &default_value() const noexcept¶
Friends
- friend struct ::mdds::fst::detail::forward_itr_handler< flat_segment_tree >
- friend struct ::mdds::fst::detail::reverse_itr_handler< flat_segment_tree >
-
class const_iterator : public mdds::fst::detail::const_iterator_base<flat_segment_tree, ::mdds::fst::detail::forward_itr_handler<flat_segment_tree>>¶
Public Functions
-
inline const_iterator()¶
-
const_segment_iterator to_segment() const¶
Create a segment iterator that references the same segment the source iterator references the start key of.
-
inline const_iterator()¶
-
class const_reverse_iterator : public mdds::fst::detail::const_iterator_base<flat_segment_tree, ::mdds::fst::detail::reverse_itr_handler<flat_segment_tree>>¶
Public Functions
-
inline const_reverse_iterator()¶
-
inline const_reverse_iterator()¶
-
class const_segment_range_type¶
-
struct leaf_value_type¶
Public Functions
-
inline bool operator==(const leaf_value_type &r) const noexcept(noexcept(std::declval<value_type>() == std::declval<value_type>()))¶
-
inline bool operator!=(const leaf_value_type &r) const noexcept(noexcept(!operator==(r)))¶
-
inline leaf_value_type()¶
Public Members
-
value_type value¶
-
inline bool operator==(const leaf_value_type &r) const noexcept(noexcept(std::declval<value_type>() == std::declval<value_type>()))¶
-
struct nonleaf_value_type¶
Public Functions
-
inline bool operator==(const nonleaf_value_type&) const noexcept¶
-
inline bool operator==(const nonleaf_value_type&) const noexcept¶
-
typedef size_t size_type¶