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

Bit matrix for graph connectivity. More...

#include <tpl_matgraph.H>

Inheritance diagram for Aleph::Bit_Mat_Graph< GT, SA >:
[legend]
Collaboration diagram for Aleph::Bit_Mat_Graph< GT, SA >:
[legend]

Classes

struct  Proxy
 Proxy for bit access. More...
 

Public Types

using Graph_Type = GT
 Graph type.
 
using Node = typename GT::Node
 Node type.
 
using Arc = typename GT::Arc
 Arc type.
 

Public Member Functions

size_t get_num_nodes () const noexcept
 Get number of nodes (matrix dimension)
 
 Bit_Mat_Graph ()=default
 Default constructor (empty matrix)
 
 Bit_Mat_Graph (GT &g)
 Construct from graph.
 
 Bit_Mat_Graph (const Bit_Mat_Graph &other)
 Copy constructor.
 
 Bit_Mat_Graph (size_t dim)
 Construct with dimension only.
 
void set_list_graph (GT &g)
 Associate with a graph.
 
GTget_list_graph () noexcept
 Get pointer to associated graph (nullptr if none)
 
const GTget_list_graph () const noexcept
 Get pointer to associated graph (const)
 
Bit_Mat_Graphoperator= (const Bit_Mat_Graph &other)
 Copy assignment.
 
Bit_Mat_Graphoperator= (GT &g)
 Assign from graph.
 
Nodeoperator() (long i)
 Get node by index.
 
long operator() (Node *node) const
 Get index of node.
 
Proxy operator() (long i, long j)
 Access bit by indices.
 
Proxy operator() (long i, long j) const
 Access bit by indices (const)
 
Proxy operator() (Node *src_node, Node *tgt_node)
 Access bit by node pointers.
 
Proxy operator() (Node *src_node, Node *tgt_node) const
 Access bit by node pointers (const)
 

Private Member Functions

void copy_list_graph (GT &g)
 

Private Attributes

BitArray bit_array
 
GTlgraph = nullptr
 
DynArray< typename GT::Node * > nodes
 
size_t n = 0
 

Detailed Description

template<class GT, class SA = Dft_Show_Arc<GT>>
class Aleph::Bit_Mat_Graph< GT, SA >

Bit matrix for graph connectivity.

Bit_Mat_Graph provides a compact bit matrix representation for connectivity queries. Each entry uses only 1 bit: 1 indicates an arc exists, 0 indicates no arc.

Key Features

  • Minimal memory: n²/8 bytes for n nodes
  • O(1) edge existence check
  • Can be created without a graph (just dimension)
  • Modifiable entries

Usage Example

// ... build graph ...
Bit_Mat_Graph<decltype(g)> bits(g);
// Check connectivity
if (bits(0, 1))
std::cout << "Edge exists\n";
// Modify
bits(0, 2) = 1; // Add edge
bits(0, 1) = 0; // Remove edge
Bit matrix for graph connectivity.
Graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:428
Template Parameters
GTGraph type
SAArc filter
See also
BitArray Underlying bit array implementation
warshall_compute_transitive_closure()

Definition at line 1067 of file tpl_matgraph.H.

Member Typedef Documentation

◆ Arc

template<class GT , class SA = Dft_Show_Arc<GT>>
using Aleph::Bit_Mat_Graph< GT, SA >::Arc = typename GT::Arc

Arc type.

Definition at line 1077 of file tpl_matgraph.H.

◆ Graph_Type

template<class GT , class SA = Dft_Show_Arc<GT>>
using Aleph::Bit_Mat_Graph< GT, SA >::Graph_Type = GT

Graph type.

Definition at line 1071 of file tpl_matgraph.H.

◆ Node

template<class GT , class SA = Dft_Show_Arc<GT>>
using Aleph::Bit_Mat_Graph< GT, SA >::Node = typename GT::Node

Node type.

Definition at line 1074 of file tpl_matgraph.H.

Constructor & Destructor Documentation

◆ Bit_Mat_Graph() [1/4]

template<class GT , class SA = Dft_Show_Arc<GT>>
Aleph::Bit_Mat_Graph< GT, SA >::Bit_Mat_Graph ( )
default

Default constructor (empty matrix)

◆ Bit_Mat_Graph() [2/4]

template<class GT , class SA = Dft_Show_Arc<GT>>
Aleph::Bit_Mat_Graph< GT, SA >::Bit_Mat_Graph ( GT g)
inlineexplicit

Construct from graph.

Parameters
gSource graph

Definition at line 1147 of file tpl_matgraph.H.

References Aleph::Bit_Mat_Graph< GT, SA >::copy_list_graph().

◆ Bit_Mat_Graph() [3/4]

template<class GT , class SA = Dft_Show_Arc<GT>>
Aleph::Bit_Mat_Graph< GT, SA >::Bit_Mat_Graph ( const Bit_Mat_Graph< GT, SA > &  other)
inline

Copy constructor.

Definition at line 1154 of file tpl_matgraph.H.

◆ Bit_Mat_Graph() [4/4]

template<class GT , class SA = Dft_Show_Arc<GT>>
Aleph::Bit_Mat_Graph< GT, SA >::Bit_Mat_Graph ( size_t  dim)
inlineexplicit

Construct with dimension only.

Parameters
dimMatrix dimension

Definition at line 1163 of file tpl_matgraph.H.

Member Function Documentation

◆ copy_list_graph()

◆ get_list_graph() [1/2]

template<class GT , class SA = Dft_Show_Arc<GT>>
const GT * Aleph::Bit_Mat_Graph< GT, SA >::get_list_graph ( ) const
inlinenoexcept

Get pointer to associated graph (const)

Definition at line 1183 of file tpl_matgraph.H.

References Aleph::Bit_Mat_Graph< GT, SA >::lgraph.

◆ get_list_graph() [2/2]

template<class GT , class SA = Dft_Show_Arc<GT>>
GT * Aleph::Bit_Mat_Graph< GT, SA >::get_list_graph ( )
inlinenoexcept

Get pointer to associated graph (nullptr if none)

Definition at line 1180 of file tpl_matgraph.H.

References Aleph::Bit_Mat_Graph< GT, SA >::lgraph.

Referenced by TEST_F(), TEST_F(), TEST_F(), and Aleph::warshall_compute_transitive_clausure().

◆ get_num_nodes()

template<class GT , class SA = Dft_Show_Arc<GT>>
size_t Aleph::Bit_Mat_Graph< GT, SA >::get_num_nodes ( ) const
inlinenoexcept

Get number of nodes (matrix dimension)

Definition at line 1138 of file tpl_matgraph.H.

References Aleph::Bit_Mat_Graph< GT, SA >::n.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), and Aleph::warshall_compute_transitive_clausure().

◆ operator()() [1/6]

template<class GT , class SA = Dft_Show_Arc<GT>>
Node * Aleph::Bit_Mat_Graph< GT, SA >::operator() ( long  i)
inline

Get node by index.

Parameters
iNode index
Returns
Pointer to node
Exceptions
std::domain_errorif no graph associated
std::out_of_rangeif index out of bounds

Definition at line 1213 of file tpl_matgraph.H.

References ah_domain_error_if, Aleph::Bit_Mat_Graph< GT, SA >::lgraph, and Aleph::Bit_Mat_Graph< GT, SA >::nodes.

◆ operator()() [2/6]

template<class GT , class SA = Dft_Show_Arc<GT>>
Proxy Aleph::Bit_Mat_Graph< GT, SA >::operator() ( long  i,
long  j 
)
inline

Access bit by indices.

Definition at line 1234 of file tpl_matgraph.H.

◆ operator()() [3/6]

template<class GT , class SA = Dft_Show_Arc<GT>>
Proxy Aleph::Bit_Mat_Graph< GT, SA >::operator() ( long  i,
long  j 
) const
inline

Access bit by indices (const)

Definition at line 1240 of file tpl_matgraph.H.

◆ operator()() [4/6]

template<class GT , class SA = Dft_Show_Arc<GT>>
long Aleph::Bit_Mat_Graph< GT, SA >::operator() ( Node node) const
inline

Get index of node.

Parameters
nodeNode pointer
Returns
Index in matrix
Exceptions
std::domain_errorif no graph associated

Definition at line 1226 of file tpl_matgraph.H.

References ah_domain_error_if, Aleph::Bit_Mat_Graph< GT, SA >::lgraph, Aleph::Bit_Mat_Graph< GT, SA >::n, and Aleph::Bit_Mat_Graph< GT, SA >::nodes.

◆ operator()() [5/6]

template<class GT , class SA = Dft_Show_Arc<GT>>
Proxy Aleph::Bit_Mat_Graph< GT, SA >::operator() ( Node src_node,
Node tgt_node 
)
inline

◆ operator()() [6/6]

template<class GT , class SA = Dft_Show_Arc<GT>>
Proxy Aleph::Bit_Mat_Graph< GT, SA >::operator() ( Node src_node,
Node tgt_node 
) const
inline

◆ operator=() [1/2]

◆ operator=() [2/2]

template<class GT , class SA = Dft_Show_Arc<GT>>
Bit_Mat_Graph & Aleph::Bit_Mat_Graph< GT, SA >::operator= ( GT g)
inline

◆ set_list_graph()

Member Data Documentation

◆ bit_array

◆ lgraph

◆ n

◆ nodes


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