Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag > Class Template Reference

Link-Cut Tree with edge weights and path aggregations. More...

#include <tpl_link_cut_tree_with_edges.H>

Inheritance diagram for Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >:
[legend]
Collaboration diagram for Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >:
[legend]

Classes

struct  EdgeKey
 
struct  EdgeKeyEq
 
struct  EdgeKeyHash
 
struct  EdgeRec
 
struct  ExportData
 Data stored in each exported Tree_Node. More...
 
struct  NodePtrEq
 

Public Types

using Node = typename InternalLCT::Node
 Opaque vertex handle (same type as internal LCT node).
 

Public Member Functions

 Gen_Link_Cut_Tree_WithEdges ()=default
 Default constructor for an empty Link-Cut Tree with edges.
 
 Gen_Link_Cut_Tree_WithEdges (const Gen_Link_Cut_Tree_WithEdges &)=delete
 Deleted copy constructor.
 
Gen_Link_Cut_Tree_WithEdgesoperator= (const Gen_Link_Cut_Tree_WithEdges &)=delete
 Deleted copy assignment.
 
 Gen_Link_Cut_Tree_WithEdges (Gen_Link_Cut_Tree_WithEdges &&)=delete
 Deleted move constructor.
 
Gen_Link_Cut_Tree_WithEdgesoperator= (Gen_Link_Cut_Tree_WithEdges &&)=delete
 Deleted move assignment.
 
Nodemake_vertex (const VT &val=VT{})
 Create an isolated vertex.
 
size_t size () const noexcept
 Total number of user vertices (excluding internal edge nodes).
 
size_t num_components () const noexcept
 Number of connected components.
 
size_t num_edges () const noexcept
 Number of edges in the forest.
 
const VTget_vertex_val (Node *x) const
 Read the stored payload of a user vertex.
 
void set_vertex_val (Node *x, const VT &val)
 Replace the stored payload of a user vertex.
 
bool connected (Node *u, Node *v)
 Test whether u and v are in the same tree.
 
void link (Node *u, Node *v, const ET &weight)
 Add an edge (u, v) with weight weight.
 
void cut (Node *u, Node *v)
 Remove the edge between u and v.
 
ET path_query (Node *u, Node *v)
 Aggregate edge values on the path from u to v.
 
void make_root (Node *x)
 Make x the root of its represented tree.
 
Nodefind_root (Node *x)
 Find the root of the tree containing x.
 
size_t path_size (Node *u, Node *v)
 Number of user vertices on the path from u to v.
 
void set_edge_val (Node *u, Node *v, const ET &new_weight)
 Update the weight of an existing edge (u, v).
 
const ETget_edge_val (Node *u, Node *v)
 Read the weight of an existing edge (u, v).
 
Tree_Node< ExportData > * export_to_tree_node (Node *root)
 Export the represented tree rooted at root as a Tree_Node.
 

Private Types

using InternalLCT = Gen_Link_Cut_Tree< ET, EdgeMonoid, LazyTag >
 

Private Member Functions

size_t find_edge_idx (Node *u, Node *v) const noexcept
 
void remove_edge_at (size_t idx)
 
const VTlookup_vertex_val (Node *nd) const
 
void require_vertex (Node *x) const
 

Static Private Member Functions

static size_t edge_key_hash (const EdgeKey &key) noexcept
 
static size_t node_ptr_hash (Node *const &nd) noexcept
 
static EdgeKey make_edge_key (Node *u, Node *v) noexcept
 

Private Attributes

InternalLCT lct_
 
Array< EdgeRecedge_recs_
 
DynMapHash< EdgeKey, size_t, EdgeKeyEqedge_idx_
 
DynMapHash< Node *, VT, NodePtrEqvertex_vals_
 
size_t n_vertices_ = 0
 
size_t n_components_ = 0
 

Detailed Description

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
requires LCTMonoid<EdgeMonoid, ET>
class Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >

Link-Cut Tree with edge weights and path aggregations.

Template Parameters
VTVertex payload type (stored but not aggregated).
ETEdge value type (aggregated via EdgeMonoid).
EdgeMonoidAssociative combiner for edge aggregation.
LazyTagLazy-tag policy for deferred edge updates.

Definition at line 82 of file tpl_link_cut_tree_with_edges.H.

Member Typedef Documentation

◆ InternalLCT

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
using Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::InternalLCT = Gen_Link_Cut_Tree<ET, EdgeMonoid, LazyTag>
private

Definition at line 84 of file tpl_link_cut_tree_with_edges.H.

◆ Node

Opaque vertex handle (same type as internal LCT node).

Definition at line 88 of file tpl_link_cut_tree_with_edges.H.

Constructor & Destructor Documentation

◆ Gen_Link_Cut_Tree_WithEdges() [1/3]

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::Gen_Link_Cut_Tree_WithEdges ( )
default

Default constructor for an empty Link-Cut Tree with edges.

◆ Gen_Link_Cut_Tree_WithEdges() [2/3]

Deleted copy constructor.

◆ Gen_Link_Cut_Tree_WithEdges() [3/3]

Deleted move constructor.

Member Function Documentation

◆ connected()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
bool Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::connected ( Node u,
Node v 
)
inline

Test whether u and v are in the same tree.

Exceptions
std::invalid_argumentif either handle is null.
std::domain_errorif either handle does not belong to this tree.

Definition at line 278 of file tpl_link_cut_tree_with_edges.H.

References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::connected(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::lct_, and Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::require_vertex().

Referenced by TEST().

◆ cut()

◆ edge_key_hash()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
static size_t Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::edge_key_hash ( const EdgeKey key)
inlinestaticprivatenoexcept

Definition at line 126 of file tpl_link_cut_tree_with_edges.H.

◆ export_to_tree_node()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
Tree_Node< ExportData > * Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::export_to_tree_node ( Node root)
inline

Export the represented tree rooted at root as a Tree_Node.

Materializes the forest component containing root into an explicit n-ary tree of Tree_Node<ExportData>. Each exported node stores a back-pointer to the original LCT vertex and the weight of the edge to its parent (the root stores EdgeMonoid::identity()).

The caller owns the returned tree and must free it with destroy_tree(result).

Parameters
rootVertex to use as the root.
Returns
Newly allocated Tree_Node<ExportData> *.
Exceptions
std::invalid_argumentif root is null.
Complexity
O(E log V) where E is the number of managed edges and V is the number of vertices in the component.

Definition at line 485 of file tpl_link_cut_tree_with_edges.H.

References Aleph::and, Aleph::Array< T >::append(), Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::connected(), Primes::DefaultPrime, destroy_tree(), Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::edge_recs_, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::get_val(), Aleph::DynMapHashTable< Key, Data, HashTable, Cmp >::insert(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::lct_, Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::lookup_vertex_val(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::make_root(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::node_ptr_hash(), r, Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::require_vertex(), root(), Aleph::DynMapHashTable< Key, Data, HashTable, Cmp >::search(), Aleph::Array< T >::size(), and w.

◆ find_edge_idx()

◆ find_root()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
Node * Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::find_root ( Node x)
inline

Find the root of the tree containing x.

Note
After rerooting via make_root(), the root is always a vertex node.
Exceptions
std::invalid_argumentif x is null.
std::domain_errorif x does not belong to this tree.

Definition at line 400 of file tpl_link_cut_tree_with_edges.H.

References Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::find_root(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::lct_, and Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::require_vertex().

◆ get_edge_val()

◆ get_vertex_val()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
const VT & Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::get_vertex_val ( Node x) const
inline

Read the stored payload of a user vertex.

Exceptions
std::invalid_argumentif x is null.
std::domain_errorif x does not belong to this tree.

Definition at line 257 of file tpl_link_cut_tree_with_edges.H.

References Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::lookup_vertex_val().

◆ link()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
void Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::link ( Node u,
Node v,
const ET weight 
)
inline

◆ lookup_vertex_val()

◆ make_edge_key()

◆ make_root()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
void Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::make_root ( Node x)
inline

◆ make_vertex()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
Node * Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::make_vertex ( const VT val = VT{})
inline

Create an isolated vertex.

The vertex payload is stored in the wrapper while the internal LCT node carries EdgeMonoid::identity() so it stays transparent to edge aggregation.

Parameters
valVertex payload stored alongside the opaque handle.
Returns
Stable handle to the new vertex.

Definition at line 220 of file tpl_link_cut_tree_with_edges.H.

Referenced by TEST(), and TEST().

◆ node_ptr_hash()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
static size_t Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::node_ptr_hash ( Node *const nd)
inlinestaticprivatenoexcept

◆ num_components()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
size_t Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::num_components ( ) const
inlinenoexcept

Number of connected components.

Definition at line 241 of file tpl_link_cut_tree_with_edges.H.

References Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::n_components_.

◆ num_edges()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
size_t Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::num_edges ( ) const
inlinenoexcept

Number of edges in the forest.

Definition at line 247 of file tpl_link_cut_tree_with_edges.H.

References Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::edge_recs_.

◆ operator=() [1/2]

Deleted copy assignment.

◆ operator=() [2/2]

Deleted move assignment.

◆ path_query()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
ET Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::path_query ( Node u,
Node v 
)
inline

Aggregate edge values on the path from u to v.

Since vertex nodes carry EdgeMonoid::identity(), the returned value reflects only edge weights along the path.

Exceptions
std::invalid_argumentif either handle is null.
std::domain_errorif u and v are not connected.

Definition at line 374 of file tpl_link_cut_tree_with_edges.H.

References Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::lct_, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_query(), and Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::require_vertex().

Referenced by TEST().

◆ path_size()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
size_t Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::path_size ( Node u,
Node v 
)
inline

Number of user vertices on the path from u to v.

Internally each represented edge becomes a hidden node, so the wrapped LCT reports a path length of 2k - 1 for a visible path with k vertices. This wrapper translates the internal count back to the public vertex count.

Exceptions
std::domain_errorif either handle does not belong to this tree.

Definition at line 415 of file tpl_link_cut_tree_with_edges.H.

References Aleph::divide_and_conquer_partition_dp(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::lct_, Aleph::Gen_Link_Cut_Tree< T, Monoid, LazyTag >::path_size(), and Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::require_vertex().

◆ remove_edge_at()

◆ require_vertex()

◆ set_edge_val()

◆ set_vertex_val()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
void Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::set_vertex_val ( Node x,
const VT val 
)
inline

Replace the stored payload of a user vertex.

Exceptions
std::invalid_argumentif x is null.
std::domain_errorif x does not belong to this tree.

Definition at line 267 of file tpl_link_cut_tree_with_edges.H.

References Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::require_vertex(), and Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::vertex_vals_.

◆ size()

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
size_t Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::size ( ) const
inlinenoexcept

Total number of user vertices (excluding internal edge nodes).

Definition at line 238 of file tpl_link_cut_tree_with_edges.H.

References Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::n_vertices_.

Member Data Documentation

◆ edge_idx_

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
DynMapHash<EdgeKey, size_t, EdgeKeyEq> Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::edge_idx_
private

◆ edge_recs_

◆ lct_

◆ n_components_

◆ n_vertices_

template<typename VT = int, typename ET = int, class EdgeMonoid = DefaultMonoid<ET>, class LazyTag = NoLazyTag<ET>>
size_t Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::n_vertices_ = 0
private

◆ vertex_vals_


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