|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Index of the arcs that go into each node of a graph. More...
#include <tpl_graph.H>
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 |
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
}
| GT | the graph type. |
| SA | the arc filter, which the index uses only while it is built. |
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.
|
private |
Definition at line 2226 of file tpl_graph.H.
|
private |
Definition at line 2225 of file tpl_graph.H.
|
inline |
Index the arcs of g into each node that sa shows.
| [in] | g | the graph. |
| [in] | sa | the arc filter, called once on each arc of g. |
| bad_alloc | if there is no memory for the index. |
| anything | that sa throws. |
Definition at line 2384 of file tpl_graph.H.
References Aleph::In_Arcs_Index< GT, SA >::arcs, Aleph::Array< T >::create(), Aleph::In_Arcs_Index< GT, SA >::first, GraphCommon< GT, Node, Arc >::get_num_arcs(), k, Aleph::In_Arcs_Index< GT, SA >::keys, m, Aleph::In_Arcs_Index< GT, SA >::mask(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), Aleph::In_Arcs_Index< GT, SA >::number, Aleph::In_Arcs_Index< GT, SA >::number_of(), Aleph::In_Arcs_Index< GT, SA >::place_of(), Aleph::Array< T >::putn(), and Aleph::Array< T >::size().
|
default |
Copy another index.
| [in] | other | the index to copy. |
| bad_alloc | if there is no memory for the copy. |
|
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.
| [in,out] | other | the index to move from. |
| bad_alloc | if 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().
|
inlineprivate |
Definition at line 2265 of file tpl_graph.H.
References ah_domain_error_if, Aleph::In_Arcs_Index< GT, SA >::first, Aleph::In_Arcs_Index< GT, SA >::number_of(), and Aleph::Array< T >::size().
Referenced by Aleph::In_Arcs_Index< GT, SA >::get_it(), and Aleph::In_Arcs_Index< GT, SA >::in_degree().
|
inline |
Return an iterator on the arcs into p that the filter showed.
| [in] | p | a node of the graph. |
| domain_error | if 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().
|
inline |
Return the number of arcs into p that the filter showed.
| [in] | p | a node of the graph. |
| domain_error | if 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().
|
inlineprivatenoexcept |
Definition at line 2254 of file tpl_graph.H.
References Aleph::In_Arcs_Index< GT, SA >::bits.
Referenced by Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index(), and Aleph::In_Arcs_Index< GT, SA >::number_of().
|
inlineprivatenoexcept |
Definition at line 2257 of file tpl_graph.H.
References Aleph::In_Arcs_Index< GT, SA >::first, Aleph::In_Arcs_Index< GT, SA >::keys, Aleph::In_Arcs_Index< GT, SA >::mask(), Aleph::In_Arcs_Index< GT, SA >::number, Aleph::In_Arcs_Index< GT, SA >::place_of(), and Aleph::Array< T >::size().
Referenced by Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index(), and Aleph::In_Arcs_Index< GT, SA >::checked_number_of().
|
default |
Copy another index.
| [in] | other | the index to copy. |
| bad_alloc | if there is no memory for the copy. |
|
inlinenoexcept |
Exchange this index with another, which is left with the previous arcs of this one.
| [in,out] | other | the index to move from. |
Definition at line 2467 of file tpl_graph.H.
References Aleph::In_Arcs_Index< GT, SA >::swap().
|
inlineprivatenoexcept |
Definition at line 2248 of file tpl_graph.H.
References Aleph::In_Arcs_Index< GT, SA >::bits.
Referenced by Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index(), and Aleph::In_Arcs_Index< GT, SA >::number_of().
|
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().
|
inlinenoexcept |
Exchange in \(O(1)\) this index and another.
| [in,out] | other | the index to exchange with. |
Definition at line 2477 of file tpl_graph.H.
References Aleph::In_Arcs_Index< GT, SA >::arcs, Aleph::In_Arcs_Index< GT, SA >::bits, Aleph::In_Arcs_Index< GT, SA >::first, Aleph::In_Arcs_Index< GT, SA >::keys, Aleph::In_Arcs_Index< GT, SA >::number, and Aleph::Array< T >::swap().
Referenced by Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index(), and Aleph::In_Arcs_Index< GT, SA >::operator=().
|
inlinestaticprivatenoexcept |
Definition at line 2240 of file tpl_graph.H.
|
private |
Definition at line 2238 of file tpl_graph.H.
Referenced by Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index(), Aleph::In_Arcs_Index< GT, SA >::get_it(), Aleph::In_Arcs_Index< GT, SA >::size(), and Aleph::In_Arcs_Index< GT, SA >::swap().
|
private |
Definition at line 2231 of file tpl_graph.H.
Referenced by Aleph::In_Arcs_Index< GT, SA >::mask(), Aleph::In_Arcs_Index< GT, SA >::place_of(), and Aleph::In_Arcs_Index< GT, SA >::swap().
|
private |
Definition at line 2237 of file tpl_graph.H.
Referenced by Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index(), Aleph::In_Arcs_Index< GT, SA >::checked_number_of(), Aleph::In_Arcs_Index< GT, SA >::get_it(), Aleph::In_Arcs_Index< GT, SA >::in_degree(), Aleph::In_Arcs_Index< GT, SA >::number_of(), and Aleph::In_Arcs_Index< GT, SA >::swap().
|
private |
Definition at line 2232 of file tpl_graph.H.
Referenced by Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index(), Aleph::In_Arcs_Index< GT, SA >::number_of(), and Aleph::In_Arcs_Index< GT, SA >::swap().
|
private |
Definition at line 2233 of file tpl_graph.H.
Referenced by Aleph::In_Arcs_Index< GT, SA >::In_Arcs_Index(), Aleph::In_Arcs_Index< GT, SA >::number_of(), and Aleph::In_Arcs_Index< GT, SA >::swap().