NAME
Data::Graph::Shared - Shared-memory directed weighted graph for Linux
SYNOPSIS
use Data::Graph::Shared;
my $g = Data::Graph::Shared->new(undef, 100, 500); # 100 nodes, 500 edges
my $a = $g->add_node(10); # returns node index
my $b = $g->add_node(20);
my $c = $g->add_node(30);
$g->add_edge($a, $b, 5); # a→b weight 5
$g->add_edge($a, $c, 3); # a→c weight 3
$g->add_edge($b, $c, 1); # b→c weight 1
my @nbrs = $g->neighbors($a); # ([1,5], [2,3]) — [dst, weight] pairs
say $g->degree($a); # 2
say $g->node_data($a); # 10
$g->remove_node($b); # removes node and outgoing edges
DESCRIPTION
Directed weighted graph in shared memory. Nodes allocated from a bitmap pool, edges stored as adjacency lists in a separate edge pool. Mutex-protected mutations with PID-based stale recovery.
Note: remove_node removes the node and its outgoing edges only. Incoming edges from other nodes are NOT automatically removed — callers must remove them explicitly if needed. This is an O(1) design choice; full incoming-edge cleanup would require O(E) traversal.
Linux-only. Requires 64-bit Perl.
METHODS
my $id = $g->add_node($data); # returns node index or undef
$g->add_edge($src, $dst); # weight defaults to 1
$g->add_edge($src, $dst, $weight);
$g->remove_node($id);
$g->has_node($id);
$g->node_data($id);
$g->set_node_data($id, $data);
my @pairs = $g->neighbors($id); # list of [$dst, $weight]
$g->each_neighbor($id, sub { my ($dst, $w) = @_ });
$g->degree($id);
my @ids = $g->nodes; # all node indices
$g->node_count; $g->edge_count;
$g->max_nodes; $g->max_edges;
$g->path; $g->stats;
BENCHMARKS
Single-process (10K ops, x86_64 Linux, Perl 5.40):
add_node 3.9M/s
add_edge (random) 2.3M/s
has_node 13.3M/s
node_data 5.5M/s
neighbors 2.6M/s
degree 5.6M/s
STATS
stats() returns: node_count, edge_count, max_nodes, max_edges, ops, mmap_size.
SECURITY
The mmap region is writable by all processes that open it. Do not share backing files with untrusted processes.
SEE ALSO
Data::Heap::Shared - priority queue (for Dijkstra, Prim, etc.)
Data::Pool::Shared - fixed-size object pool
Data::HashMap::Shared - concurrent hash table
Data::Buffer::Shared - typed shared array
Data::Queue::Shared - FIFO queue
Data::Stack::Shared - LIFO stack
Data::Deque::Shared - double-ended queue
Data::Log::Shared - append-only log
Data::Sync::Shared - synchronization primitives
Data::PubSub::Shared - publish-subscribe ring
Data::ReqRep::Shared - request-reply
AUTHOR
vividsnow
LICENSE
Same terms as Perl itself.