LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
User-defined literals in LAL

Construction of trees from head vectors

The C++ implementation of the library, offers three quick and useful ways of constructing free and rooted trees in a single line using head vectors (see Head vector for a definition of head vectors).

To start with, recall that there exist functions that convert a head vector into a free tree (see lal::graphs::from_head_vector_to_free_tree) or a rooted tree (see lal::graphs::from_head_vector_to_rooted_tree). The former returns a pair of lal::graphs::free_tree and lal::node, and the latter a lal::graphs::rooted_tree.

const std::pair<lal::graphs::free_tree, lal::node> tree_and_root = lal::graphs::from_head_vector_to_free_tree({0,1,1,1,1,1,1});
Rooted tree graph class.
Definition rooted_tree.hpp:109
rooted_tree from_head_vector_to_rooted_tree(const head_vector &hv, const bool normalize=true, const bool check=true) noexcept
Converts a head vector into a rooted tree.
std::pair< free_tree, node > from_head_vector_to_free_tree(const head_vector &hv, const bool normalize=true, const bool check=true) noexcept
Converts a head vector into a rooted tree.

In LAL there are defined two literal types to ease the construction of these objects.

const std::pair<lal::graphs::free_tree, lal::node> tree_and_root = "0 1 1 1 1 1 1"_pfree_tree;
const lal::graphs::rooted_tree tree = "0 1 1 1 1 1 1"_rooted_tree;

Attention! Notice the p before free_tree in the literal.

Since, when creating a free tree, we often only want the tree structure (and ignore the root denoted explicitly in the head vector with the '0' character), users can write

const lal::graphs::free_tree tree_and_root = "0 1 1 1 1 1 1"_pfree_tree.first;
Free tree graph class.
Definition free_tree.hpp:60

or simply

const lal::graphs::free_tree tree_and_root = "0 1 1 1 1 1 1"_free_tree;

Attention! Notice that there is no p before free_tree in this literal.