Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Gen_HLD_Path_Query< GT, T, Op, SA > Class Template Reference

Segment-tree-powered path/subtree queries over an HLD layout. More...

#include <Tree_Decomposition.H>

Collaboration diagram for Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >:
[legend]

Public Types

using Node = typename GT::Node
 

Public Member Functions

 Gen_HLD_Path_Query (const GT &g, Node *root, const T &identity, Op op=Op(), SA sa=SA())
 Construct from graph/root using node->get_info() as initial values.
 
 Gen_HLD_Path_Query (const GT &g, const T &identity, Op op=Op(), SA sa=SA())
 Construct from graph (first node as root) using node->get_info().
 
template<class Getter >
requires std::invocable<Getter, Node *>
and std::convertible_to< std::invoke_result_t< Getter, Node * >, T > Gen_HLD_Path_Query (const GT &g, Node *root, Getter getter, const T &identity, Op op=Op(), SA sa=SA())
 Construct with custom node-to-value getter.
 
template<class Getter >
requires std::invocable<Getter, Node *>
and std::convertible_to< std::invoke_result_t< Getter, Node * >, T > Gen_HLD_Path_Query (const GT &g, Getter getter, const T &identity, Op op=Op(), SA sa=SA())
 Construct with custom getter and implicit root (first node).
 
 Gen_HLD_Path_Query (const Gen_HLD_Path_Query &other)=default
 Copy the decomposition and the values of another engine.
 
 Gen_HLD_Path_Query (Gen_HLD_Path_Query &&other)=default
 Take the decomposition and the values of another engine, which is left empty.
 
Gen_HLD_Path_Query & operator= (const Gen_HLD_Path_Query &other)=default
 Copy the decomposition and the values of another engine.
 
Gen_HLD_Path_Query & operator= (Gen_HLD_Path_Query &&other) noexcept(noexcept(swap(other)))
 Exchange this engine with another, which is left with the previous tree and values of this one.
 
void swap (Gen_HLD_Path_Query &other) noexcept(std::is_nothrow_swappable_v< T > and std::is_nothrow_swappable_v< Op > and std::is_nothrow_move_assignable_v< Gen_Heavy_Light_Decomposition< GT, SA > >)
 Exchange in O(1) this engine and another.
 
const Gen_Heavy_Light_Decomposition< GT, SA > & decomposition () const noexcept
 
size_t size () const noexcept
 
bool is_empty () const noexcept
 
T query_path_id (const size_t u, const size_t v) const
 Path query between two node IDs in O(log^2 n).
 
T query_path (const Node *u, const Node *v) const
 Path query between two nodes in O(log^2 n).
 
T query_subtree_id (const size_t id) const
 Subtree query for node ID in O(log n).
 
T query_subtree (const Node *node) const
 Subtree query for node in O(log n).
 
void update_node_id (const size_t id, const T &delta)
 Point update: a[id] = Op(a[id], delta).
 
void update_node (const Node *node, const T &delta)
 Point update: a[node] = Op(a[node], delta).
 
void set_node_id (const size_t id, const T &value)
 Point assignment: a[id] = value.
 
void set_node (const Node *node, const T &value)
 Point assignment: a[node] = value.
 
T get_node_id (const size_t id) const
 Return current value at node ID.
 
T get_node (const Node *node) const
 Return current value at node.
 

Private Member Functions

void ensure_not_empty (const char *where) const
 
void swap_all_or_none (Gen_HLD_Path_Query &other)
 

Static Private Member Functions

template<class Getter >
requires std::invocable<Getter, Node *>
and static std::convertible_to< std::invoke_result_t< Getter, Node * >, T > Array< T > build_base_array (const Gen_Heavy_Light_Decomposition< GT, SA > &hld, Getter getter)
 
static Array< T > build_base_from_node_info (const Gen_Heavy_Light_Decomposition< GT, SA > &hld)
 

Private Attributes

Gen_Heavy_Light_Decomposition< GT, SA > hld_
 
Gen_Segment_Tree< T, Op > segment_tree_
 
T identity_
 
Op op_
 

Detailed Description

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
class Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >

Segment-tree-powered path/subtree queries over an HLD layout.

This class combines Gen_Heavy_Light_Decomposition with Gen_Segment_Tree for convenient dynamic queries.

Supported operations:

  • query_path(u, v)
  • query_subtree(u)
  • update_node(u, delta)
  • set_node(u, value)
  • get_node(u)
Note
query_path() combines segment answers with Op and therefore assumes this fold is valid for your query semantics. For non-commutative path queries, use for_each_path_segment_id() from Gen_Heavy_Light_Decomposition and handle direction explicitly.
Template Parameters
GTGraph type.
TSegment value type.
OpAssociative operation.
SAArc filter type.

Definition at line 879 of file Tree_Decomposition.H.

Member Typedef Documentation

◆ Node

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::Node = typename GT::Node

Definition at line 882 of file Tree_Decomposition.H.

Constructor & Destructor Documentation

◆ Gen_HLD_Path_Query() [1/6]

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::Gen_HLD_Path_Query ( const GT &  g,
Node *  root,
const T &  identity,
Op  op = Op(),
SA  sa = SA() 
)
inline

Construct from graph/root using node->get_info() as initial values.

Definition at line 926 of file Tree_Decomposition.H.

◆ Gen_HLD_Path_Query() [2/6]

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::Gen_HLD_Path_Query ( const GT &  g,
const T &  identity,
Op  op = Op(),
SA  sa = SA() 
)
inline

Construct from graph (first node as root) using node->get_info().

Definition at line 940 of file Tree_Decomposition.H.

◆ Gen_HLD_Path_Query() [3/6]

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
template<class Getter >
requires std::invocable<Getter, Node *>
and std::convertible_to< std::invoke_result_t< Getter, Node * >, T > Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::Gen_HLD_Path_Query ( const GT &  g,
Node *  root,
Getter  getter,
const T &  identity,
Op  op = Op(),
SA  sa = SA() 
)
inline

Construct with custom node-to-value getter.

Definition at line 956 of file Tree_Decomposition.H.

◆ Gen_HLD_Path_Query() [4/6]

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
template<class Getter >
requires std::invocable<Getter, Node *>
and std::convertible_to< std::invoke_result_t< Getter, Node * >, T > Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::Gen_HLD_Path_Query ( const GT &  g,
Getter  getter,
const T &  identity,
Op  op = Op(),
SA  sa = SA() 
)
inline

Construct with custom getter and implicit root (first node).

Definition at line 974 of file Tree_Decomposition.H.

◆ Gen_HLD_Path_Query() [5/6]

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::Gen_HLD_Path_Query ( const Gen_HLD_Path_Query< GT, T, Op, SA > &  other)
default

Copy the decomposition and the values of another engine.

Parameters
[in]otherengine to copy.

◆ Gen_HLD_Path_Query() [6/6]

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::Gen_HLD_Path_Query ( Gen_HLD_Path_Query< GT, T, Op, SA > &&  other)
default

Take the decomposition and the values of another engine, which is left empty.

The decomposition of the moved-from engine is empty, so that the engine never queries the segment tree that the move leaves to it.

Parameters
[in,out]otherengine to move from.

Member Function Documentation

◆ build_base_array()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
template<class Getter >
requires std::invocable<Getter, Node *>
and static std::convertible_to< std::invoke_result_t< Getter, Node * >, T > Array< T > Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::build_base_array ( const Gen_Heavy_Light_Decomposition< GT, SA > &  hld,
Getter  getter 
)
inlinestaticprivate

◆ build_base_from_node_info()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
static Array< T > Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::build_base_from_node_info ( const Gen_Heavy_Light_Decomposition< GT, SA > &  hld)
inlinestaticprivate

◆ decomposition()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
const Gen_Heavy_Light_Decomposition< GT, SA > & Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::decomposition ( ) const
inlinenoexcept

◆ ensure_not_empty()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::ensure_not_empty ( const char *  where) const
inlineprivate

◆ get_node()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
T Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::get_node ( const Node *  node) const
inline

◆ get_node_id()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
T Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::get_node_id ( const size_t  id) const
inline

◆ is_empty()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
bool Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::is_empty ( ) const
inlinenoexcept

◆ operator=() [1/2]

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Gen_HLD_Path_Query & Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::operator= ( const Gen_HLD_Path_Query< GT, T, Op, SA > &  other)
default

Copy the decomposition and the values of another engine.

Parameters
[in]otherengine to copy.
Returns
this engine.

◆ operator=() [2/2]

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Gen_HLD_Path_Query & Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::operator= ( Gen_HLD_Path_Query< GT, T, Op, SA > &&  other)
inlinenoexcept

Exchange this engine with another, which is left with the previous tree and values of this one.

The implicit assignment left the segment tree to its own move assignment, which exchanged its array but copied its size, and copied the identity: the moved-from engine then queried the tree that it received with the size of its own.

Parameters
[in,out]otherengine to move from.
Returns
this engine.

Definition at line 1019 of file Tree_Decomposition.H.

References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap().

◆ query_path()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
T Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path ( const Node *  u,
const Node *  v 
) const
inline

◆ query_path_id()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
T Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path_id ( const size_t  u,
const size_t  v 
) const
inline

◆ query_subtree()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
T Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_subtree ( const Node *  node) const
inline

◆ query_subtree_id()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
T Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_subtree_id ( const size_t  id) const
inline

◆ set_node()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::set_node ( const Node *  node,
const T &  value 
)
inline

◆ set_node_id()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::set_node_id ( const size_t  id,
const T &  value 
)
inline

◆ size()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::size ( ) const
inlinenoexcept

◆ swap()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap ( Gen_HLD_Path_Query< GT, T, Op, SA > &  other)
inlinenoexcept

Exchange in O(1) this engine and another.

Parameters
[in,out]otherengine to exchange with.
Exceptions
whatswapping the values, the operations or the filters throws. The values and the operations are exchanged first, and then the segment trees and the decompositions, each all or none: if a swap throws, those before it are exchanged back, and both engines are left as they were, if the swap that threw left its arguments as they were. If a swap that puts one back throws too, both engines can only be destroyed or assigned.

Definition at line 1037 of file Tree_Decomposition.H.

References Aleph::and, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::identity_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::op_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::segment_tree_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap_all_or_none().

Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::operator=(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap_all_or_none().

◆ swap_all_or_none()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap_all_or_none ( Gen_HLD_Path_Query< GT, T, Op, SA > &  other)
inlineprivate

◆ update_node()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::update_node ( const Node *  node,
const T &  delta 
)
inline

◆ update_node_id()

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::update_node_id ( const size_t  id,
const T &  delta 
)
inline

Member Data Documentation

◆ hld_

◆ identity_

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
T Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::identity_
private

◆ op_

template<AlephGraph GT, typename T = typename GT::Node::Node_Type, class Op = Aleph::plus<T>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Op Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::op_
private

◆ segment_tree_


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