24 #ifndef PPL_CO_Tree_defs_hh
25 #define PPL_CO_Tree_defs_hh 1
33 #ifndef PPL_CO_TREE_EXTRA_DEBUG
34 #ifdef PPL_ABI_BREAKING_EXTRA_DEBUG
35 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
45 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
46 #define PPL_CO_TREE_EXTRA_DEBUG 1
47 #else // !defined(PPL_ABI_BREAKING_EXTRA_DEBUG)
48 #define PPL_CO_TREE_EXTRA_DEBUG 0
49 #endif // !defined(PPL_ABI_BREAKING_EXTRA_DEBUG)
50 #endif // !defined(PPL_CO_TREE_EXTRA_DEBUG)
55 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
102 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
115 "height_t is too small to store depths.");
267 data_type_const_reference
operator*()
const;
299 #if PPL_CO_TREE_EXTRA_DEBUG
428 data_type_const_reference
operator*()
const;
460 #if PPL_CO_TREE_EXTRA_DEBUG
501 template <
typename Iterator>
646 data_type_const_reference
data);
955 data_type_const_reference
data,
966 data_type_const_reference
data,
985 data_type_const_reference
data);
1134 data_type_const_reference
value);
1195 data_type_const_reference
value,
1473 Coefficient_traits::const_reference
operator*()
const;
1518 height_t
depth()
const;
1537 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
1540 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
1543 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
1546 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
1549 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
1552 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
1560 #endif // !defined(PPL_CO_Tree_defs_hh)
dimension_type index() const
Returns the index of the element pointed to by *this.
void increase_keys_from(dimension_type key, dimension_type n)
Adds n to all keys greater than or equal to key.
bool is_root() const
Returns true if the pointed node is the root node.
void dump_tree() const
Dumps the tree to stdout, for debugging purposes.
std::bidirectional_iterator_tag iterator_category
bool operator!=(const iterator &x) const
Compares *this with x .
data_type & operator*()
Returns the key and value of the current node.
void m_swap(iterator &itr)
Swaps itr with *this.
void swap(CO_Tree &x, CO_Tree &y)
dimension_type key() const
Returns the index of the node pointed to by *this.
Coefficient data_type
The type of the data elements associated with keys.
void init(dimension_type n)
Initializes a tree with reserved size at least n .
size_t dimension_type
An unsigned integral type for representing space dimensions.
bool OK() const
Checks the internal invariants.
static void dump_subtree(tree_iterator itr)
Dumps the subtree rooted at itr to stdout, for debugging purposes.
static unsigned integer_log2(dimension_type n)
Returns the floor of the base-2 logarithm of n .
static bool is_greater_than_ratio(dimension_type numer, dimension_type denom, dimension_type ratio)
Compares the fractions numer/denom with ratio/100.
void destroy()
Deallocates the tree's dynamic arrays.
bool OK() const
Checks the internal invariant.
dimension_type get_offset() const
Returns 2^h, with h the height of the current node in the tree, counting from 0.
dimension_type dfs_index() const
Returns the index of the current node in the DFS layout of the complete tree.
void get_parent()
Makes the iterator point to the parent of the current node.
static const dimension_type max_density_percent
The maximum density of used nodes.
iterator begin()
Returns an iterator that points at the first element.
data_type * data
The vector that contains the data of the keys in the tree.
bool operator==(const iterator &x) const
Compares *this with x .
bool is_right_child() const
Returns true if the pointed node has a parent and is its right child.
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
bool is_leaf() const
Returns true if the pointed node is a leaf of the complete tree.
An iterator on the tree elements, ordered by key.
dimension_type * indexes
The vector that contains the keys in the tree.
static dimension_type max_size()
Returns the size() of the largest possible CO_Tree.
const_iterator & operator++()
Navigates to the next element.
const data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
static const dimension_type min_leaf_density_percent
The minimum density at the leaves' depth.
void m_swap(const_iterator &itr)
Swaps itr with *this.
unsigned height_t
This is used for node heights and depths in the tree.
std::allocator< data_type > data_allocator
The allocator used to allocate/deallocate data.
tree_iterator insert_precise_aux(dimension_type key, data_type_const_reference data, tree_iterator itr)
Helper for insert_precise.
dimension_type size() const
Returns the number of elements stored in the tree.
void m_swap(CO_Tree &x)
Swaps x with *this.
iterator & operator=(const iterator &itr)
Assigns itr to *this .
const iterator & end()
Returns an iterator that points after the last element.
const_iterator & operator--()
Navigates to the previous element.
const_iterator()
Constructs an invalid const_iterator.
iterator bisect_in(iterator first, iterator last, dimension_type key)
Searches an element with key key in [first, last] using bisection.
void get_left_child()
Makes the iterator point to the left child of the current node.
CO_Tree & operator=(const CO_Tree &y)
The assignment operator.
tree_iterator rebalance(tree_iterator itr, dimension_type key, data_type_const_reference value)
Rebalances the tree.
bool empty() const
Returns true if the tree has no elements.
iterator insert(dimension_type key)
Inserts an element in the tree.
dimension_type reserved_size
The number of nodes in the complete tree.
const_iterator cbegin() const
Returns a const_iterator that points at the first element.
bool operator==(const const_iterator &x) const
Compares *this with x .
std::ptrdiff_t difference_type
data_type & operator*()
Returns the current element.
#define sizeof_to_bits(size)
tree_iterator & operator=(const tree_iterator &itr)
The assignment operator.
iterator cached_end
The iterator returned by end().
static const dimension_type min_density_percent
The minimum density of used nodes.
A cache-oblivious binary search tree of pairs.
~CO_Tree()
The destructor.
bool operator==(const tree_iterator &itr) const
Compares *this with itr.
dimension_type offset
This is 2^h, with h the height of the current node in the tree, counting from 0.
iterator bisect(dimension_type key)
Searches an element with key key using bisection.
const_iterator cached_const_end
The iterator returned by the const version of end().
void follow_left_children_with_value()
Follows left children with a value, until it arrives at a leaf or at a node with no value...
tree_iterator(CO_Tree &tree)
Constructs a tree_iterator pointing at the root node of the specified tree.
dimension_type compact_elements_in_the_rightmost_end(dimension_type last_in_subtree, dimension_type subtree_size, dimension_type key, data_type_const_reference value, bool add_element)
Moves all elements of a subtree to the rightmost end.
bool OK() const
Checks the internal invariants, in debug mode only.
const const_iterator & cend() const
Returns a const_iterator that points after the last element.
std::bidirectional_iterator_tag iterator_category
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
dimension_type dfs_index(const_iterator itr) const
static bool is_less_than_ratio(dimension_type numer, dimension_type denom, dimension_type ratio)
Compares the fractions numer/denom with ratio/100.
bool OK() const
Checks the internal invariants, in debug mode only.
iterator & operator++()
Navigates to the next element in the tree.
CO_Tree & tree
The tree containing the element pointed to by this iterator.
bool operator!=(const const_iterator &x) const
Compares *this with x .
data_type_const_reference reference
std::ptrdiff_t difference_type
dimension_type & index()
Returns a reference to the index of the element pointed to by *this.
bool operator!=(const tree_iterator &itr) const
Compares *this with itr.
tree_iterator insert_precise(dimension_type key, data_type_const_reference data, tree_iterator itr)
Inserts an element in the tree.
Coefficient_traits::const_reference data_type_const_reference
The entire library is confined to this namespace.
A const iterator on the tree elements, ordered by key.
iterator()
Constructs an invalid iterator.
height_t depth() const
Returns the depth of the current node in the complete tree.
void rebuild_bigger_tree()
Increases the tree's reserved size.
data_type_const_reference operator*() const
Returns the current element.
void clear()
Removes all elements from the tree.
static void move_data_element(data_type &to, data_type &from)
Moves the value of from in to .
PPL_COMPILE_TIME_CHECK(C_Integer< height_t >::max >=sizeof_to_bits(sizeof(dimension_type)),"height_t is too small to store depths.")
void get_root()
Makes the iterator point to the root of tree.
void refresh_cached_iterators()
Re-initializes the cached iterators.
static dimension_type count_used_in_subtree(tree_iterator itr)
Counts the number of used elements in the subtree rooted at itr.
dimension_type size_
The number of values stored in the tree.
void insert_in_empty_tree(dimension_type key, data_type_const_reference data)
Inserts an element in the tree.
bool structure_OK() const
Checks the internal invariants, but not the densities.
void follow_right_children_with_value()
Follows right children with a value, until it arrives at a leaf or at a node with no value...
const_iterator & operator=(const const_iterator &itr)
Assigns itr to *this .
iterator erase(dimension_type key)
Erases the element with key key from the tree.
void erase_element_and_shift_left(dimension_type key)
Removes the element with key key (if it exists) and decrements by 1 all elements' keys that were grea...
const dimension_type * current_index
A pointer to the corresponding element of the tree's indexes[] array.
iterator bisect_near(iterator hint, dimension_type key)
Searches an element with key key near hint.
dimension_type index() const
Returns the index of the element pointed to by *this.
void move_data_from(CO_Tree &tree)
Moves all data in the tree tree into *this.
height_t max_depth
The depth of the leaves in the complete tree.
dimension_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
void redistribute_elements_in_subtree(dimension_type root_index, dimension_type subtree_size, dimension_type last_used, dimension_type key, data_type_const_reference value, bool add_element)
Redistributes the elements in the subtree rooted at root_index.
void fast_shift(dimension_type i, iterator itr)
static const dimension_type unused_index
An index used as a marker for unused nodes in the tree.
iterator & operator--()
Navigates to the previous element in the tree.
const data_type value_type
void rebuild_smaller_tree()
Decreases the tree's reserved size.
void get_right_child()
Makes the iterator point to the right child of the current node.
void copy_data_from(const CO_Tree &tree)
Copies all data in the tree tree into *this.
dimension_type i
The index of the current node in the DFS layout of the complete tree.
CO_Tree()
Constructs an empty tree.
data_type * current_data
A pointer to the corresponding element of the tree's data[] array.
void go_down_searching_key(dimension_type key)
Searches for an element with key key in the subtree rooted at *this.