]>
jfr.im git - irc/quakenet/newserv.git/blob - patricia/patricia_alloc.c
5 #include "../core/nsmalloc.h"
9 patricia_node_t
*node_freelist
;
10 union prefixes
*prefix_freelist
;
12 prefix_t
*newprefix() {
13 union prefixes
*prefixes
= prefix_freelist
;
17 prefixes
=(union prefixes
*)nsmalloc(POOL_PATRICIA
,ALLOCUNIT
*sizeof(prefix_t
));
19 for (i
=0;i
<(ALLOCUNIT
-1);i
++) {
20 prefixes
[i
].next
=&(prefixes
[i
+1]);
22 prefixes
[ALLOCUNIT
-1].next
=NULL
;
25 prefix_freelist
= prefixes
->next
;
26 return &(prefixes
->prefix
);
30 void freeprefix (prefix_t
*prefix
) {
31 union prefixes
*ups
= (union prefixes
*)prefix
;
32 ups
->next
= prefix_freelist
;
33 prefix_freelist
= ups
;
37 patricia_node_t
*newnode() {
39 patricia_node_t
*node
;
41 if( node_freelist
==NULL
) {
42 node_freelist
=(patricia_node_t
*)nsmalloc(POOL_PATRICIA
,ALLOCUNIT
*sizeof(patricia_node_t
));
44 for (i
=0;i
<(ALLOCUNIT
-1);i
++) {
45 node_freelist
[i
].parent
=(patricia_node_t
*)&(node_freelist
[i
+1]);
47 node_freelist
[ALLOCUNIT
-1].parent
=NULL
;
51 node_freelist
=(patricia_node_t
*)node
->parent
;
56 void freenode (patricia_node_t
*node
) {
57 node
->parent
=(patricia_node_t
*)node_freelist
;