39# ifndef TPL_GRAPH_INDEXES_H
40# define TPL_GRAPH_INDEXES_H
116template <
class GT,
class Compare = Dft_Node_Cmp<GT>,
117 template <
typename,
class>
class Tree =
Treap,
134 typedef DynSetTree <GT_Node *, Tree, Compare>
Tree_Type;
148 this->
insert(it.get_curr());
186 if (this->
insert(p) ==
nullptr)
224 if (this->
insert(p) ==
nullptr)
274 if (ret_val ==
nullptr)
289 GT_Node * dummy_node_ptr = &dummy_node;
291 return search(dummy_node_ptr);
326template <
class GT,
class Compare = Dft_Arc_Cmp<GT>,
327 template <
typename,
class>
class Tree =
Treap,
354 typedef DynSetTree <typename GT::Arc *, Tree, Compare>
Tree_Type;
368 this->
insert(it.get_curr());
412 if (this->
insert(a) ==
nullptr)
447 auto * key =
new GT_Arc(info);
453 if (ret_val !=
nullptr)
467 std::swap(key->src_node, key->tgt_node);
470 if (ret_val ==
nullptr)
496 return search(src, tgt, info);
Builds an arc index for fast lookup by source/target nodes.
GT::Node_Type GT_Node_Info
Typedef for the graph's node info type.
DynSetTree< typename GT::Arc *, Tree, Compare > Tree_Type
Typedef for the internal tree type.
GT_Arc * insert_in_graph(GT_Node *src, GT_Node *tgt, const GT_Arc_Info &&info=GT_Arc_Info())
Inserts an arc into the graph and index (rvalue overload).
GT_Arc * search(GT_Node *src, GT_Node *tgt, const GT_Arc_Info &info)
Searches for an arc by its source, target, and content.
GT_Arc * insert_in_graph(GT_Node *src, GT_Node *tgt, const GT_Arc_Info &info)
Inserts an arc into the graph and index.
GT::Arc_Type GT_Arc_Info
Typedef for the graph's arc info type.
GT & g
Reference to the graph being indexed.
GT::Arc GT_Arc
Typedef for the graph's arc type.
GT::Node GT_Node
Typedef for the graph's node type.
GT_Arc * search(GT_Node *src, GT_Node *tgt, const GT_Arc_Info &&info=GT_Arc_Info())
Searches for an arc by its source, target, and content (rvalue overload).
void init(SA &sa)
Initializes the index by inserting the arcs of the graph that sa shows.
void remove_from_graph(GT_Arc *a)
Removes an arc from the graph and index.
Arcs_Index(GT &_g, Compare &cmp, SA &_sa)
Constructor.
Arcs_Index(GT &_g, Compare &&cmp=Compare(), SA &&_sa=SA())
Constructor with default comparison and filter objects.
Dynamic set backed by balanced binary search trees with automatic memory management.
Key & find(const Key &key)
Returns a modifiable reference to an element within the set.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
size_t remove(const Key &key)
Removes a key from the dynamic set.
Key * search(const Key &key)
Find an element in the set.
Key * search_or_insert(const Key &key)
Look for the key in the binary search tree or inserts it if it is not found.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
typename Node::Node_Type Node_Type
The arc class type.
virtual void remove_arc(Arc *arc) noexcept
Remove an arc from the graph and free it.
virtual void remove_node(Node *node)
Remove a node from the graph and free its memory.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
typename Arc::Arc_Type Arc_Type
The type of data stored in the arc.
Filtered iterator on the nodes of a graph.
Builds a node index for fast lookup and retrieval.
GT & g
Reference to the graph being indexed.
Nodes_Index(GT &_g, Compare &&cmp=Compare(), SN &&_sn=SN())
Constructor with rvalue references for comparison and filter.
GT::Node_Type GT_Node_Info
Typedef for the graph's node info type.
GT::Node GT_Node
Typedef for the graph's node type.
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(const GT_Node_Info &&info=GT_Node_Info())
Inserts a node with generic content into the graph and index (rvalue overload).
GT_Node * search(const GT_Node_Info &info)
Searches for a node by its content (info overload).
GT_Node * insert_in_graph(GT_Node *p)
Inserts a node into the graph and index.
Nodes_Index(GT &_g, Compare &cmp, SN &_sn)
Constructor that initializes the index with existing graph nodes.
GT_Node * search(GT_Node *p)
Searches for a node by its content.
DynSetTree< GT_Node *, Tree, Compare > Tree_Type
Typedef for the internal tree type.
GT_Node * search_or_insert_in_graph(const GT_Node_Info &info)
Searches for a node with generic content in the index and graph, inserting it if not found.
void init(SN &sn)
Initialize the index by inserting the graph nodes that sn shows.
GT_Node * insert_in_graph(const GT_Node_Info &info)
Inserts a node with generic content into the graph and index.
void * tgt_node
Please don't use.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
bool is_digraph() const noexcept
Return true if the graph this is directed.
QuadTree - Hierarchical spatial index for 2D points.
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
static std::atomic< bool > init
Filtered iterator on all the arcs of a graph.
Default arc comparison class for Arcs_Index.
bool operator()(typename GT::Arc *a1, typename GT::Arc *a2) const
Comparison operator.
Default node comparison class for Nodes_Index.
bool operator()(typename GT::Node *p1, typename GT::Node *p2) const
Comparison operator.
Default filter for filtered iterators on arcs.
Default filter for the graph nodes.
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
Dynamic set implementations based on balanced binary search trees.
Generic graph and digraph implementations.