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

Index of the arcs that go into each node of a graph. More...

#include <tpl_graph.H>

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

Classes

class  Iterator
 Iterator on the arcs into a node, in the order of the arc iterator of the graph when the index was built. More...
 

Public Member Functions

 In_Arcs_Index (const GT &g, SA sa=SA())
 Index the arcs of g into each node that sa shows.
 
 In_Arcs_Index (const In_Arcs_Index &other)=default
 Copy another index.
 
 In_Arcs_Index (In_Arcs_Index &&other)
 Take the arcs of another index, which is left as the index of a graph without nodes.
 
In_Arcs_Index & operator= (const In_Arcs_Index &other)=default
 Copy another index.
 
In_Arcs_Index & operator= (In_Arcs_Index &&other) noexcept
 Exchange this index with another, which is left with the previous arcs of this one.
 
void swap (In_Arcs_Index &other) noexcept
 Exchange in \(O(1)\) this index and another.
 
size_t size () const noexcept
 Return the number of arcs of the index: those that the filter showed.
 
size_t in_degree (const Node *p) const
 Return the number of arcs into p that the filter showed.
 
Iterator get_it (const Node *p) const
 Return an iterator on the arcs into p that the filter showed.
 

Private Types

using Node = typename GT::Node
 
using Arc = typename GT::Arc
 

Private Member Functions

size_t place_of (const Node *p) const noexcept
 
size_t mask () const noexcept
 
size_t number_of (const Node *p) const noexcept
 
size_t checked_number_of (const Node *p) const
 

Static Private Member Functions

static unsigned table_bits (const size_t n) noexcept
 

Private Attributes

unsigned bits = 1
 
Array< Node * > keys
 
Array< size_t > number
 
Array< size_t > first
 
Array< Arc * > arcs
 

Detailed Description

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
class Aleph::In_Arcs_Index< GT, SA >

Index of the arcs that go into each node of a graph.

A digraph keeps each arc only in the list of its source, so that In_Iterator(g, p) and in_degree(g, p) walk all the arcs of the graph for each node. In_Arcs_Index walks them once, in \(O(V + E)\) expected, and keeps for each node the arcs whose target is the node and that the filter shows, in the order of the arc iterator of the graph; a loop is one arc into its node. Then in_degree(p) takes \(O(1)\), and the iterator of get_it(p) \(O(1)\) per arc, besides finding p in a table, \(O(1)\) expected.

The index reads the target of each arc, so that it works on every kind of graph, directed or not, and on a graph of an undirected type that says that it is directed (see set_digraph()): on a graph that is not directed it gives the arcs that In_Iterator(p) gives. It does not use the cookies or the counters of the nodes. It is a picture of the graph when it is built: it does not see the arcs inserted or removed later, and it must not be used once the nodes or the arcs that it has are gone.

Example:

In_Arcs_Index<GT> in(g);
for (auto it = in.get_it(p); it.has_curr(); it.next_ne())
  {
    auto a = it.get_curr_ne(); // an arc into p
    auto q = it.get_node_ne(); // its source
  }
Template Parameters
GTthe graph type.
SAthe arc filter, which the index uses only while it is built.
See also
In_Iterator
Note
A growing std::vector copies these objects instead of moving them: their move constructor is not noexcept, because it leaves the source empty and usable, which allocates, and std::vector moves only what cannot throw. The containers of Aleph do not copy them to grow: Array moves its items, and DynList and DynArray never relocate them.

Definition at line 2223 of file tpl_graph.H.

Member Typedef Documentation

◆ Arc

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::In_Arcs_Index< GT, SA >::Arc = typename GT::Arc
private

Definition at line 2226 of file tpl_graph.H.

◆ Node

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::In_Arcs_Index< GT, SA >::Node = typename GT::Node
private

Definition at line 2225 of file tpl_graph.H.

Constructor & Destructor Documentation

◆ In_Arcs_Index() [1/3]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index ( const GT &  g,
SA  sa = SA() 
)
inline

◆ In_Arcs_Index() [2/3]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index ( const In_Arcs_Index< GT, SA > &  other)
default

Copy another index.

Parameters
[in]otherthe index to copy.
Exceptions
bad_allocif there is no memory for the copy.

◆ In_Arcs_Index() [3/3]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index ( In_Arcs_Index< GT, SA > &&  other)
inline

Take the arcs of another index, which is left as the index of a graph without nodes.

The implicit move took the arrays but copied the size of the table: the moved-from index then looked for the nodes in a table that it no longer had. A search reads the table without a check, so that other is left as the index of a graph without nodes, whose two places are empty; number, read only at the places of nodes, stays empty.

Parameters
[in,out]otherthe index to move from.
Exceptions
bad_allocif there is no memory for the table left to other, which is then unchanged.

Definition at line 2448 of file tpl_graph.H.

References Aleph::In_Arcs_Index< GT, SA >::swap().

Member Function Documentation

◆ checked_number_of()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::In_Arcs_Index< GT, SA >::checked_number_of ( const Node *  p) const
inlineprivate

◆ get_it()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Iterator Aleph::In_Arcs_Index< GT, SA >::get_it ( const Node *  p) const
inline

Return an iterator on the arcs into p that the filter showed.

Parameters
[in]pa node of the graph.
Exceptions
domain_errorif p was not a node of the graph.

Definition at line 2506 of file tpl_graph.H.

References Aleph::In_Arcs_Index< GT, SA >::arcs, Aleph::Array< T >::base(), Aleph::In_Arcs_Index< GT, SA >::checked_number_of(), and Aleph::In_Arcs_Index< GT, SA >::first.

Referenced by TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< In_Arcs_Index< Dgraph > >::use().

◆ in_degree()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::In_Arcs_Index< GT, SA >::in_degree ( const Node *  p) const
inline

Return the number of arcs into p that the filter showed.

Parameters
[in]pa node of the graph.
Exceptions
domain_errorif p was not a node of the graph.

Definition at line 2495 of file tpl_graph.H.

References Aleph::In_Arcs_Index< GT, SA >::checked_number_of(), and Aleph::In_Arcs_Index< GT, SA >::first.

Referenced by TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< In_Arcs_Index< Dgraph > >::use().

◆ mask()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::In_Arcs_Index< GT, SA >::mask ( ) const
inlineprivatenoexcept

◆ number_of()

◆ operator=() [1/2]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
In_Arcs_Index & Aleph::In_Arcs_Index< GT, SA >::operator= ( const In_Arcs_Index< GT, SA > &  other)
default

Copy another index.

Parameters
[in]otherthe index to copy.
Returns
this index.
Exceptions
bad_allocif there is no memory for the copy.

◆ operator=() [2/2]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
In_Arcs_Index & Aleph::In_Arcs_Index< GT, SA >::operator= ( In_Arcs_Index< GT, SA > &&  other)
inlinenoexcept

Exchange this index with another, which is left with the previous arcs of this one.

Parameters
[in,out]otherthe index to move from.
Returns
this index.

Definition at line 2467 of file tpl_graph.H.

References Aleph::In_Arcs_Index< GT, SA >::swap().

◆ place_of()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::In_Arcs_Index< GT, SA >::place_of ( const Node *  p) const
inlineprivatenoexcept

◆ size()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::In_Arcs_Index< GT, SA >::size ( ) const
inlinenoexcept

Return the number of arcs of the index: those that the filter showed.

Definition at line 2488 of file tpl_graph.H.

References Aleph::In_Arcs_Index< GT, SA >::arcs, and Aleph::Array< T >::size().

Referenced by Moved_From_Case< In_Arcs_Index< Dgraph > >::is_empty(), and Moved_From_Case< In_Arcs_Index< Dgraph > >::use().

◆ swap()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::In_Arcs_Index< GT, SA >::swap ( In_Arcs_Index< GT, SA > &  other)
inlinenoexcept

◆ table_bits()

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
static unsigned Aleph::In_Arcs_Index< GT, SA >::table_bits ( const size_t  n)
inlinestaticprivatenoexcept

Definition at line 2240 of file tpl_graph.H.

Member Data Documentation

◆ arcs

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Array<Arc *> Aleph::In_Arcs_Index< GT, SA >::arcs
private

◆ bits

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
unsigned Aleph::In_Arcs_Index< GT, SA >::bits = 1
private

◆ first

◆ keys

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Array<Node *> Aleph::In_Arcs_Index< GT, SA >::keys
private

◆ number

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Array<size_t> Aleph::In_Arcs_Index< GT, SA >::number
private

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