38#include <gtest/gtest.h>
51TEST(NodesIndex, InsertSearchRemoveByInfo)
57 ASSERT_NE(n10,
nullptr);
60 ASSERT_NE(n20,
nullptr);
62 ASSERT_EQ(index.
search(10), n10);
63 ASSERT_EQ(index.
search(20), n20);
64 ASSERT_EQ(index.
search(30),
nullptr);
67 ASSERT_EQ(index.
search(10),
nullptr);
68 ASSERT_EQ(index.
search(20), n20);
71TEST(NodesIndex, SearchOrInsertDoesNotDuplicate)
78 ASSERT_EQ(n10_a, n10_b);
81TEST(ArcsIndex, DirectedSearchByEndpointsAndInfo)
86 auto * n1 = g.insert_node(1);
87 auto * n2 = g.insert_node(2);
89 auto * a12 =
arcs.insert_in_graph(n1, n2, 5);
90 ASSERT_NE(a12,
nullptr);
92 ASSERT_EQ(
arcs.search(n1, n2, 5), a12);
93 ASSERT_EQ(
arcs.search(n2, n1, 5),
nullptr);
96TEST(ArcsIndex, UndirectedSearchFindsReverse)
104 auto * a12 =
arcs.insert_in_graph(n1, n2, 5);
105 ASSERT_NE(a12,
nullptr);
107 ASSERT_EQ(
arcs.search(n1, n2, 5), a12);
108 ASSERT_EQ(
arcs.search(n2, n1, 5), a12);
111TEST(ArcsIndex, RemoveFromGraphRemovesFromIndex)
119 auto * a12 =
arcs.insert_in_graph(n1, n2, 5);
120 ASSERT_NE(a12,
nullptr);
121 ASSERT_EQ(
arcs.search(n1, n2, 5), a12);
123 arcs.remove_from_graph(a12);
124 ASSERT_EQ(
arcs.search(n1, n2, 5),
nullptr);
Builds an arc index for fast lookup by source/target nodes.
Generic directed graph (digraph) wrapper template.
Graph implemented with double-linked adjacency lists.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Builds a node index for fast lookup and retrieval.
GT_Node * search_or_insert_in_graph(GT_Node *p)
Searches for a node in the index and graph, inserting it if not found.
void remove_from_graph(GT_Node *p)
Removes a node from the graph and index.
GT_Node * insert_in_graph(GT_Node *p)
Inserts a node into the graph and index.
GT_Node * search(GT_Node *p)
Searches for a node by its content.
DynArray< Graph::Arc * > arcs
Main namespace for Aleph-w library functions.
Arc of graph implemented with double-linked adjacency lists.
Generic graph and digraph implementations.
Graph node and arc indexing.