Recti 1.2.4
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
recti::Tree Class Reference

Arena-allocated tree of TreeNodes. More...

#include <dme_algorithm.hpp>

Public Member Functions

 Tree ()=default
 
NodeIdx add (TreeNode node)
 Adds a node to the arena and returns its index.
 
const TreeNodeget (NodeIdx idx) const
 Returns a const reference to the node at the given index.
 
TreeNodeget_mut (NodeIdx idx)
 Returns a mutable reference to the node at the given index.
 
std::pair< TreeNode &, TreeNode & > get_pair_mut (NodeIdx a, NodeIdx b)
 Simultaneously returns mutable references to two distinct nodes.
 
std::size_t size () const
 Number of nodes in the arena.
 
bool empty () const
 True when the arena holds no nodes.
 

Public Attributes

NodeIdx root = SIZE_MAX
 

Detailed Description

Arena-allocated tree of TreeNodes.

Nodes are stored in a contiguous std::vector and referenced by their NodeIdx index. This avoids std::shared_ptr overhead, improves cache locality, and allows safe simultaneous mutation of two distinct nodes via get_pair_mut.

Constructor & Destructor Documentation

◆ Tree()

recti::Tree::Tree ( )
default

Member Function Documentation

◆ add()

NodeIdx recti::Tree::add ( TreeNode  node)
inline

Adds a node to the arena and returns its index.

Parameters
nodeThe node to add.
Returns
The index of the newly added node.

◆ empty()

bool recti::Tree::empty ( ) const
inline

True when the arena holds no nodes.

◆ get()

const TreeNode & recti::Tree::get ( NodeIdx  idx) const
inline

Returns a const reference to the node at the given index.

◆ get_mut()

TreeNode & recti::Tree::get_mut ( NodeIdx  idx)
inline

Returns a mutable reference to the node at the given index.

◆ get_pair_mut()

std::pair< TreeNode &, TreeNode & > recti::Tree::get_pair_mut ( NodeIdx  a,
NodeIdx  b 
)
inline

Simultaneously returns mutable references to two distinct nodes.

Safe because distinct vector elements are independent in C++.

Exceptions
std::out_of_rangeif either index is out of bounds.

◆ size()

std::size_t recti::Tree::size ( ) const
inline

Number of nodes in the arena.

Member Data Documentation

◆ root

NodeIdx recti::Tree::root = SIZE_MAX

Index of the root node, or SIZE_MAX if the tree is empty.


The documentation for this class was generated from the following file: