38#include <gtest/gtest.h>
56 return (a->get_info() % 2) == 0;
66TEST(IndexArcUndirected, SearchIsSymmetric)
75 EXPECT_EQ(idx.
size(), 1u);
76 EXPECT_EQ(idx.
search(n1, n2), a);
77 EXPECT_EQ(idx.
search(n2, n1), a);
82TEST(IndexArcDirected, SearchRespectsDirection)
85 auto n1 = g.insert_node(1);
86 auto n2 = g.insert_node(2);
87 auto a12 = g.insert_arc(n1, n2, 10);
91 EXPECT_EQ(idx.
size(), 1u);
92 EXPECT_EQ(idx.
search(n1, n2), a12);
93 EXPECT_EQ(idx.
search(n2, n1),
nullptr);
95 auto a21 = g.insert_arc(n2, n1, 20);
97 EXPECT_EQ(idx.
size(), 2u);
98 EXPECT_EQ(idx.
search(n2, n1), a21);
109 EXPECT_EQ(idx.
size(), 0u);
111 EXPECT_EQ(idx.
insert(a), a);
112 EXPECT_EQ(idx.
size(), 1u);
114 EXPECT_EQ(idx.
insert(a), a);
115 EXPECT_EQ(idx.
size(), 1u);
128 dummy->src_node = n1;
129 dummy->tgt_node = n2;
130 EXPECT_EQ(idx.
insert(dummy), dummy);
131 EXPECT_EQ(idx.
size(), 1u);
134 EXPECT_EQ(idx.
insert(a), dummy);
135 EXPECT_EQ(idx.
size(), 1u);
148 EXPECT_EQ(idx.
size(), 0u);
152 EXPECT_EQ(idx.
size(), 1u);
153 EXPECT_EQ(idx.
search(n1, n2), a);
159 EXPECT_EQ(idx.
size(), 0u);
160 EXPECT_EQ(idx.
search(n1, n2),
nullptr);
179 EXPECT_EQ(idx.
size(), 0u);
197 EXPECT_EQ(idx.size(), 1u);
198 EXPECT_EQ(idx.search(n2, n3), a23);
199 EXPECT_EQ(idx.search(n1, n2),
nullptr);
Generic directed graph (digraph) wrapper template.
Index for fast arc lookup by its endpoint nodes.
GT_Arc * search(void *src, void *tgt) const
Search an arc that connects two nodes.
void build_index()
Insert into the index all arcs currently present in the graph.
GT_Arc * insert_in_graph(GT_Node *src, GT_Node *tgt, const GT_Arc_Type &info)
Create a new arc between two nodes, insert it into the graph and index it.
void remove_from_graph(GT_Arc *a)
Remove an arc from both index and graph.
void remove(GT_Arc *e)
Remove an arc from the index.
size_t size() const
Return the number of arcs currently stored in the index.
GT_Arc * search_directed(void *src, void *tgt) const
Search an arc that connects two nodes as a directed pair.
void clear_index()
Remove all arcs from the index.
GT_Arc * insert(GT_Arc *e)
Insert an arc pointer into the index.
Graph implemented with double-linked adjacency lists.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
_Graph_Arc Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
GT::Arc * search_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept(nothrow_arc_filter_v< GT, SA >)
Arc filtered searching given two nodes.
Main namespace for Aleph-w library functions.
Arc of graph implemented with double-linked adjacency lists.
Generic graph and digraph implementations.
Arc indexing for fast lookup by endpoint nodes.