Data-Graph-Shared
view release on metacpan or search on metacpan
RETVAL = graph_remove_node(h, (uint32_t)node);
OUTPUT:
RETVAL
bool
remove_node_full(self, node)
SV *self
UV node
PREINIT:
EXTRACT_GRAPH(self);
CODE:
RETVAL = graph_remove_node_full(h, (uint32_t)node);
OUTPUT:
RETVAL
bool
has_node(self, node)
SV *self
UV node
PREINIT:
EXTRACT_GRAPH(self);
CODE:
RETVAL = graph_has_node(h, (uint32_t)node);
OUTPUT:
RETVAL
IV
node_data(self, node)
SV *self
UV node
PREINIT:
EXTRACT_GRAPH(self);
CODE:
graph_mutex_lock(h->hdr);
REQUIRE_NODE(h, node);
RETVAL = (IV)h->node_data[(uint32_t)node];
graph_mutex_unlock(h->hdr);
OUTPUT:
RETVAL
void
set_node_data(self, node, data)
SV *self
UV node
IV data
PREINIT:
EXTRACT_GRAPH(self);
CODE:
graph_mutex_lock(h->hdr);
REQUIRE_NODE(h, node);
h->node_data[(uint32_t)node] = (int64_t)data;
__atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
graph_mutex_unlock(h->hdr);
void
neighbors(self, node)
SV *self
UV node
PREINIT:
EXTRACT_GRAPH(self);
PPCODE:
/* Collect edges under lock, then build Perl SVs outside it:
* newAV/newSVuv/newSViv can longjmp on OOM, which would leak the
* process-shared mutex to peers (no automatic cleanup for futex). */
graph_mutex_lock(h->hdr);
REQUIRE_NODE(h, node);
uint32_t deg = graph_degree(h, (uint32_t)node);
uint32_t eidx = h->node_heads[(uint32_t)node];
uint32_t *dsts = deg ? (uint32_t *)malloc(deg * sizeof(uint32_t)) : NULL;
int64_t *wts = deg ? (int64_t *)malloc(deg * sizeof(int64_t)) : NULL;
if (deg && (!dsts || !wts)) {
free(dsts); free(wts);
graph_mutex_unlock(h->hdr);
croak("neighbors: out of memory");
}
uint32_t i = 0;
while (eidx != GRAPH_NONE && i < deg) {
dsts[i] = h->edges[eidx].dst;
wts[i] = h->edges[eidx].weight;
eidx = h->edges[eidx].next;
i++;
}
graph_mutex_unlock(h->hdr);
EXTEND(SP, (SSize_t)i);
for (uint32_t j = 0; j < i; j++) {
AV *pair = newAV();
av_push(pair, newSVuv(dsts[j]));
av_push(pair, newSViv((IV)wts[j]));
PUSHs(sv_2mortal(newRV_noinc((SV *)pair)));
}
free(dsts); free(wts);
UV
degree(self, node)
SV *self
UV node
PREINIT:
EXTRACT_GRAPH(self);
CODE:
graph_mutex_lock(h->hdr);
REQUIRE_NODE(h, node);
RETVAL = graph_degree(h, (uint32_t)node);
graph_mutex_unlock(h->hdr);
OUTPUT:
RETVAL
UV
node_count(self)
SV *self
PREINIT:
EXTRACT_GRAPH(self);
CODE:
RETVAL = __atomic_load_n(&h->hdr->node_count, __ATOMIC_ACQUIRE);
OUTPUT:
RETVAL
UV
edge_count(self)
SV *self
PREINIT:
EXTRACT_GRAPH(self);
( run in 0.965 second using v1.01-cache-2.11-cpan-5511b514fd6 )