mirror of
https://github.com/bgp/bgpq4
synced 2025-02-28 08:53:11 +00:00
rename destroy to free
This commit is contained in:
28
sx_prefix.c
28
sx_prefix.c
@@ -44,7 +44,7 @@ sx_prefix_alloc(struct sx_prefix *p)
|
|||||||
{
|
{
|
||||||
struct sx_prefix *sp;
|
struct sx_prefix *sp;
|
||||||
|
|
||||||
if ((sp = malloc(sizeof(struct sx_prefix)) == NULL)
|
if ((sp = malloc(sizeof(struct sx_prefix))) == NULL)
|
||||||
err(1, NULL);
|
err(1, NULL);
|
||||||
|
|
||||||
if (p)
|
if (p)
|
||||||
@@ -56,7 +56,7 @@ sx_prefix_alloc(struct sx_prefix *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sx_prefix_destroy(struct sx_prefix *p)
|
sx_prefix_free(struct sx_prefix *p)
|
||||||
{
|
{
|
||||||
if (p)
|
if (p)
|
||||||
free(p);
|
free(p);
|
||||||
@@ -263,17 +263,20 @@ sx_radix_tree_insert_specifics(struct sx_radix_tree *t, struct sx_prefix *p,
|
|||||||
unsigned min, unsigned max)
|
unsigned min, unsigned max)
|
||||||
{
|
{
|
||||||
struct sx_prefix *np;
|
struct sx_prefix *np;
|
||||||
|
struct sx_radix_node *nn;
|
||||||
|
|
||||||
np = sx_prefix_alloc(p);
|
np = sx_prefix_alloc(p);
|
||||||
|
|
||||||
if (np->masklen >= min) {
|
if (np->masklen >= min) {
|
||||||
struct sx_radix_node *nn = sx_radix_tree_insert(t, np);
|
nn = sx_radix_tree_insert(t, np);
|
||||||
sx_prefix_destroy(np);
|
sx_prefix_free(np);
|
||||||
np = nn->prefix;
|
np = nn->prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (np->masklen + 1 > max)
|
if (np->masklen + 1 > max)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
||||||
np->masklen += 1;
|
np->masklen += 1;
|
||||||
sx_radix_tree_insert_specifics(t, np, min, max);
|
sx_radix_tree_insert_specifics(t, np, min, max);
|
||||||
sx_prefix_setbit(np, np->masklen);
|
sx_prefix_setbit(np, np->masklen);
|
||||||
@@ -379,7 +382,7 @@ sx_prefix_new(int af, char *text)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!sx_prefix_parse(p, af, text)) {
|
if (!sx_prefix_parse(p, af, text)) {
|
||||||
sx_prefix_destroy(p);
|
sx_prefix_free(p);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -727,7 +730,7 @@ next:
|
|||||||
char pbuffer[128], cbuffer[128];
|
char pbuffer[128], cbuffer[128];
|
||||||
sx_prefix_snprintf(prefix, pbuffer, sizeof(pbuffer));
|
sx_prefix_snprintf(prefix, pbuffer, sizeof(pbuffer));
|
||||||
sx_prefix_snprintf(chead->prefix, cbuffer, sizeof(cbuffer));
|
sx_prefix_snprintf(chead->prefix, cbuffer, sizeof(cbuffer));
|
||||||
printf("Unreachible point... eb=%i, prefix=%s, chead=%s\n",
|
printf("Unreachable point... eb=%i, prefix=%s, chead=%s\n",
|
||||||
eb, pbuffer, cbuffer);
|
eb, pbuffer, cbuffer);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@@ -738,7 +741,7 @@ struct sx_radix_node *
|
|||||||
sx_radix_tree_insert(struct sx_radix_tree *tree, struct sx_prefix *prefix)
|
sx_radix_tree_insert(struct sx_radix_tree *tree, struct sx_prefix *prefix)
|
||||||
{
|
{
|
||||||
unsigned int eb;
|
unsigned int eb;
|
||||||
struct sx_radix_node **candidate=NULL, *chead;
|
struct sx_radix_node *chead, **candidate = NULL;
|
||||||
|
|
||||||
if (!tree || !prefix)
|
if (!tree || !prefix)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -754,7 +757,7 @@ sx_radix_tree_insert(struct sx_radix_tree *tree, struct sx_prefix *prefix)
|
|||||||
candidate = &tree->head;
|
candidate = &tree->head;
|
||||||
chead = tree->head;
|
chead = tree->head;
|
||||||
|
|
||||||
next:
|
next:
|
||||||
eb = sx_prefix_eqbits(prefix, chead->prefix);
|
eb = sx_prefix_eqbits(prefix, chead->prefix);
|
||||||
if (eb < prefix->masklen && eb < chead->prefix->masklen) {
|
if (eb < prefix->masklen && eb < chead->prefix->masklen) {
|
||||||
struct sx_prefix *neoRoot = sx_prefix_alloc(prefix);
|
struct sx_prefix *neoRoot = sx_prefix_alloc(prefix);
|
||||||
@@ -763,7 +766,7 @@ next:
|
|||||||
neoRoot->masklen = eb;
|
neoRoot->masklen = eb;
|
||||||
sx_prefix_adjust_masklen(neoRoot);
|
sx_prefix_adjust_masklen(neoRoot);
|
||||||
rn=sx_radix_node_new(neoRoot);
|
rn=sx_radix_node_new(neoRoot);
|
||||||
sx_prefix_destroy(neoRoot);
|
sx_prefix_free(neoRoot);
|
||||||
neoRoot = rn->prefix;
|
neoRoot = rn->prefix;
|
||||||
if (!rn) {
|
if (!rn) {
|
||||||
sx_report(SX_ERROR,"Unable to create node: %s\n",
|
sx_report(SX_ERROR,"Unable to create node: %s\n",
|
||||||
@@ -787,11 +790,10 @@ next:
|
|||||||
return ret;
|
return ret;
|
||||||
} else if (eb == prefix->masklen && eb < chead->prefix->masklen) {
|
} else if (eb == prefix->masklen && eb < chead->prefix->masklen) {
|
||||||
struct sx_radix_node *ret = sx_radix_node_new(prefix);
|
struct sx_radix_node *ret = sx_radix_node_new(prefix);
|
||||||
if (sx_prefix_isbitset(chead->prefix, eb + 1)) {
|
if (sx_prefix_isbitset(chead->prefix, eb + 1))
|
||||||
ret->r = chead;
|
ret->r = chead;
|
||||||
} else {
|
else
|
||||||
ret->l = chead;
|
ret->l = chead;
|
||||||
}
|
|
||||||
ret->parent = chead->parent;
|
ret->parent = chead->parent;
|
||||||
chead->parent = ret;
|
chead->parent = ret;
|
||||||
*candidate = ret;
|
*candidate = ret;
|
||||||
@@ -828,7 +830,7 @@ next:
|
|||||||
char pbuffer[128], cbuffer[128];
|
char pbuffer[128], cbuffer[128];
|
||||||
sx_prefix_snprintf(prefix, pbuffer, sizeof(pbuffer));
|
sx_prefix_snprintf(prefix, pbuffer, sizeof(pbuffer));
|
||||||
sx_prefix_snprintf(chead->prefix, cbuffer, sizeof(cbuffer));
|
sx_prefix_snprintf(chead->prefix, cbuffer, sizeof(cbuffer));
|
||||||
printf("Unreachible point... eb=%i, prefix=%s, chead=%s\n", eb,
|
printf("Unreachable point... eb=%i, prefix=%s, chead=%s\n", eb,
|
||||||
pbuffer, cbuffer);
|
pbuffer, cbuffer);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ struct sx_radix_node *sx_radix_tree_lookup_exact(struct sx_radix_tree *tree,
|
|||||||
struct sx_prefix *prefix);
|
struct sx_prefix *prefix);
|
||||||
|
|
||||||
struct sx_prefix *sx_prefix_alloc(struct sx_prefix *p);
|
struct sx_prefix *sx_prefix_alloc(struct sx_prefix *p);
|
||||||
void sx_prefix_destroy(struct sx_prefix *p);
|
void sx_prefix_free(struct sx_prefix *p);
|
||||||
void sx_radix_node_destroy(struct sx_radix_node *p);
|
void sx_radix_node_destroy(struct sx_radix_node *p);
|
||||||
void sx_prefix_adjust_masklen(struct sx_prefix *p);
|
void sx_prefix_adjust_masklen(struct sx_prefix *p);
|
||||||
struct sx_prefix *sx_prefix_new(int af, char *text);
|
struct sx_prefix *sx_prefix_new(int af, char *text);
|
||||||
|
|||||||
Reference in New Issue
Block a user