38#include <gtest/gtest.h>
42#include <unordered_map>
56 std::vector<Node *> make_nodes(
Graph &g,
int n)
58 std::vector<Node *>
nodes;
60 for (
int i = 0; i < n; ++i)
67 int operator()(
Arc *a)
const noexcept
74 using HeapNode =
typename BinHeapType::Node;
78 std::unordered_map<Node *, HeapNode *> *map =
nullptr;
80 MapAccess() =
default;
82 explicit MapAccess(std::unordered_map<Node *, HeapNode *> &m)
noexcept
98 auto nodes = make_nodes(g, 2);
101 std::unordered_map<Node *, HeapNode *>
mapping;
105 heap.put_arc(a,
nodes[1]);
110 Arc *min_arc = heap.get_min_arc();
118 auto nodes = make_nodes(g, 2);
122 std::unordered_map<Node *, HeapNode *>
mapping;
126 heap.put_arc(a1,
nodes[1]);
127 heap.put_arc(a2,
nodes[1]);
129 Arc *min_arc = heap.get_min_arc();
137 auto nodes = make_nodes(g, 2);
141 std::unordered_map<Node *, HeapNode *>
mapping;
145 heap.put_arc(a1,
nodes[1]);
146 heap.put_arc(a2,
nodes[1]);
148 Arc *min_arc = heap.get_min_arc();
156 auto nodes = make_nodes(g, 4);
161 std::unordered_map<Node *, HeapNode *>
mapping;
165 heap.put_arc(a1,
nodes[1]);
166 heap.put_arc(a2,
nodes[2]);
167 heap.put_arc(a3,
nodes[3]);
171 extracted.push_back(heap.get_min_arc()->get_info());
172 extracted.push_back(heap.get_min_arc()->get_info());
173 extracted.push_back(heap.get_min_arc()->get_info());
182 auto nodes = make_nodes(g, 4);
187 std::unordered_map<Node *, HeapNode *>
mapping;
191 heap.put_arc(a1,
nodes[1]);
192 heap.put_arc(a2,
nodes[2]);
193 heap.put_arc(a3,
nodes[3]);
200 (
void)heap.get_min_arc();
201 (
void)heap.get_min_arc();
202 (
void)heap.get_min_arc();
211 std::mt19937
rng(123456);
212 std::uniform_int_distribution<int> node_count(2, 8);
213 std::uniform_int_distribution<int>
weight_dist(0, 100);
218 const int n = node_count(
rng);
219 auto nodes = make_nodes(g, n);
221 std::unordered_map<Node *, HeapNode *>
mapping;
226 for (
int i = 1; i < n; ++i)
230 heap.put_arc(a,
nodes[i]);
240 extracted.push_back(heap.get_min_arc()->get_info());
Arc heap for graph algorithms.
WeightedDigraph::Node Node
void empty() noexcept
empty the list
size_t size() const noexcept
Count the number of elements of the list.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Node heap without virtual destructor.
Arc of graph implemented with double-linked adjacency lists.
Generic graph and digraph implementations.