Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_indexNode.H File Reference

Node indexing for fast O(log n) lookup by key. More...

#include <tpl_dynSetTree.H>
#include <tpl_graph.H>
#include <ah-errors.H>
Include dependency graph for tpl_indexNode.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::Dft_Node_Cmp< GT >
 Default node comparison class for Nodes_Index. More...
 
class  Aleph::IndexNode< GT, Compare, Tree, SN >
 Builds an index of nodes for fast search and retrieval. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 

Detailed Description

Node indexing for fast O(log n) lookup by key.

Example: Fast node search by value
using GT = List_Graph<Graph_Node<string>, Graph_Arc<int>>;
GT g;
IndexNode<GT> node_index(g);
// Insert and index nodes
auto alice = node_index.insert_in_graph("Alice");
auto bob = node_index.insert_in_graph("Bob");
auto charlie = node_index.insert_in_graph("Charlie");
// O(log n) search by value
auto found = node_index.search("Bob");
if (found)
cout << "Found: " << found->get_info() << endl;
Example: User database with unique IDs
struct User { int id; string name; };
using UserGraph = List_Graph<Graph_Node<User>, Graph_Arc<Empty_Class>>;
// Custom comparator by ID
struct UserCmp {
bool operator()(UserGraph::Node* a, UserGraph::Node* b) const {
return a->get_info().id < b->get_info().id;
}
};
IndexNode<UserGraph, UserCmp> users(graph);
// Fast lookup by user ID
Author
Leandro Rabindranath León

Definition in file tpl_indexNode.H.