Net-Patricia
view release on metacpan or search on metacpan
Patricia.xs view on Meta::CPAN
_add(tree, family, addr, bits, data)
Net::Patricia tree
int family
char * addr
int bits
SV * data
PROTOTYPE: $$$$$
PREINIT:
prefix_t prefix;
Net__PatriciaNode node;
PPCODE:
Fill_Prefix(prefix, family, addr, bits, tree->maxbits);
node = patricia_lookup(tree, &prefix);
if (NULL != node) {
/* { */
if (node->data) {
deref_data(node->data);
}
node->data = newSVsv(data);
/* } */
PUSHs(data);
Patricia.xs view on Meta::CPAN
void
_match(tree, family, addr, bits)
Net::Patricia tree
int family
char * addr
int bits
PROTOTYPE: $$$$
PREINIT:
prefix_t prefix;
Net__PatriciaNode node;
PPCODE:
Fill_Prefix(prefix, family, addr, bits, tree->maxbits);
node = patricia_search_best(tree, &prefix);
if (NULL != node) {
XPUSHs((SV *)node->data);
} else {
XSRETURN_UNDEF;
}
void
_exact(tree, family, addr, bits)
Net::Patricia tree
int family
char * addr
int bits
PROTOTYPE: $$$$
PREINIT:
prefix_t prefix;
Net__PatriciaNode node;
PPCODE:
Fill_Prefix(prefix, family, addr, bits, tree->maxbits);
node = patricia_search_exact(tree, &prefix);
if (NULL != node) {
XPUSHs((SV *)node->data);
} else {
XSRETURN_UNDEF;
}
void
_remove(tree, family, addr, bits)
Net::Patricia tree
int family
char * addr
int bits
PROTOTYPE: $$$$
PREINIT:
prefix_t prefix;
Net__PatriciaNode node;
PPCODE:
Fill_Prefix(prefix, family, addr, bits, tree->maxbits);
node = patricia_search_exact(tree, &prefix);
if (NULL != node) {
XPUSHs(sv_mortalcopy((SV *)node->data));
deref_data(node->data);
patricia_remove(tree, node);
} else {
XSRETURN_UNDEF;
}
Patricia.xs view on Meta::CPAN
void
STORABLE_freeze(tree, cloning)
Net::Patricia tree
SV * cloning
PREINIT:
patricia_node_t *node = NULL;
struct frozen_header frozen_header;
struct frozen_node *frozen_nodes, *frozen_node;
size_t n = 0, i = 0, nd = 0;
SV *frozen_patricia;
PPCODE:
if (SvTRUE(cloning))
XSRETURN_UNDEF;
/* I do not know enough of patricia.c to
* decide whether inactive nodes can
* be present in a tree, and whether such
* nodes can be skipped while copying,
* so we copy everything and do not use
* num_active_node here. */
PATRICIA_WALK_ALL (tree->head, node) {
Patricia.xs view on Meta::CPAN
SV * tobj
SV * cloning
SV * serialized;
PREINIT:
struct frozen_patricia *frozen_patricia;
struct frozen_node *frozen_node;
struct _patricia_tree_t *tree;
patricia_node_t *node = NULL, *child, **fixup;
int n, n_calculated, i, d_index, l_index, r_index;
STRLEN len;
PPCODE:
if (SvTRUE(cloning))
XSRETURN_UNDEF;
tree = calloc(1, sizeof(*tree));
frozen_patricia = (struct frozen_patricia*)SvPV(serialized, len);
if (ntohl(frozen_patricia->header.magic) != FROZEN_MAGIC)
croak("Net::Patricia::STORABLE_thaw: magic mismatch");
if (frozen_patricia->header.major != FROZEN_MAJOR)
croak("Net::Patricia::STORABLE_thaw: major mismatch");
( run in 0.928 second using v1.01-cache-2.11-cpan-5511b514fd6 )