taco-db
0.1.0
|
TreeNode is the base class of all tree structures in TDB (e.g., parsing tree, logical plan, physical plan, query execution state). More...
#include <utils/tree/TreeNode.h>
Public Member Functions | |
template<class ... UniquePtrs> | |
TreeNode (NodeTag tag, UniquePtrs &&...input) | |
virtual | ~TreeNode () |
TreeNode (TreeNode &&)=default | |
TreeNode & | operator= (TreeNode &&)=default |
TreeNode (const TreeNode &)=delete | |
TreeNode & | operator= (const TreeNode &)=delete |
constexpr NodeTag | get_tag () const |
TreeNode * | get_input (size_t i) const |
template<class Node > | |
Node * | get_input_as (size_t i) const |
std::string | to_string () const |
void | node_to_string (std::string &buf, int indent) const |
Prints the node contents to a string buffer. More... | |
const char * | node_name () const |
virtual void | node_properties_to_string (std::string &buf, int indent) const =0 |
Static Public Member Functions | |
static void | append_indent (std::string &buf, int indent) |
Private Attributes | |
NodeTag | m_tag |
std::vector< std::unique_ptr< TreeNode > > | m_input |
Static Private Attributes | |
static constexpr const int | TO_STRING_INDENT_SIZE = 4 |
TreeNode is the base class of all tree structures in TDB (e.g., parsing tree, logical plan, physical plan, query execution state).
Each TreeNode can have zero or more inputs, and it owns the objects by storing a unique_ptr to it. TreeNode constructors constructors and destructors should only allocate/deallocate memory and perform initialization that may not generate an error (e.g., initializing fields with trivial constructors). Any initialization that may generate an error must be done in a separate function call, that communicates the error to the caller through the return value. Similarly, clean-up of a node that may produce some error must be done in a separate function other than the destructor with a return status.
A TreeNode object is owned by another TreeNode or some function scope that has a unique_ptr to it. As a result, a TreeNode object may only be explicitly moved as a unique_ptr or referenced through a raw pointer. It may not be shallow copied and the copy constructor and the copy assignment operator is deleted. The owner of a node is responsible to keep it alive while there are references to the object. That being said, the most common pattern is to never delete objects unless the entire tree goes is being deleted. If you need to update an input without changing the inputs of the input, most likely you'll have to replace the entire subtree anyway (since we do not allow shallow copies). The original node will be deleted when the entire tree is deleted.
Each TreeNode object is associated with a tag (NodeTag). It identifies the type of the TreeNode object. We use the tag rather than RTTI to cast or identify TreeNode – that will probably be more flexible and faster at the cost of an additional 8-byte overhead (2 bytes + padding) per node.
|
inline |
|
inlinevirtual |
|
default |
|
delete |
|
static |
|
inline |
|
inline |
|
inlineconstexpr |
|
inline |
|
pure virtual |
Implemented in taco::TempTable, taco::TableScan, taco::TableInsert, taco::TableDelete, taco::Sort, taco::Selection, taco::Projection, taco::Limit, taco::IndexScan, taco::CartesianProduct, taco::Aggregation, taco::Variable, taco::UnaryOperator, taco::OrOperator, taco::Literal, taco::FuncCallOperator, taco::Cast, taco::BinaryOperator, taco::AndOperator, taco::TempTableState, taco::TableScanState, taco::TableInsertState, taco::TableDeleteState, taco::SortState, taco::SelectionState, taco::ProjectionState, taco::LimitState, taco::IndexScanState, taco::CartesianProductState, and taco::AggregationState.
void taco::TreeNode::node_to_string | ( | std::string & | buf, |
int | indent | ||
) | const |
Prints the node contents to a string buffer.
No indentation is added on the first line, and all subsequent lines have an indentation of at least indent * INDENT_SIZE spaces.
|
inline |
|
private |
|
private |
|
staticconstexprprivate |