version 1.6, 2012/01/21 08:40:09 |
version 1.7, 2012/01/21 11:12:13 |
|
|
* a splay tree. |
* a splay tree. |
*/ |
*/ |
|
|
SPLAY_GENERATE(options_tree, options_entry, entry, options_cmp); |
RB_GENERATE(options_tree, options_entry, entry, options_cmp); |
|
|
int |
int |
options_cmp(struct options_entry *o1, struct options_entry *o2) |
options_cmp(struct options_entry *o1, struct options_entry *o2) |
|
|
void |
void |
options_init(struct options *oo, struct options *parent) |
options_init(struct options *oo, struct options *parent) |
{ |
{ |
SPLAY_INIT(&oo->tree); |
RB_INIT(&oo->tree); |
oo->parent = parent; |
oo->parent = parent; |
} |
} |
|
|
|
|
{ |
{ |
struct options_entry *o; |
struct options_entry *o; |
|
|
while (!SPLAY_EMPTY(&oo->tree)) { |
while (!RB_EMPTY(&oo->tree)) { |
o = SPLAY_ROOT(&oo->tree); |
o = RB_ROOT(&oo->tree); |
SPLAY_REMOVE(options_tree, &oo->tree, o); |
RB_REMOVE(options_tree, &oo->tree, o); |
xfree(o->name); |
xfree(o->name); |
if (o->type == OPTIONS_STRING) |
if (o->type == OPTIONS_STRING) |
xfree(o->str); |
xfree(o->str); |
|
|
struct options_entry p; |
struct options_entry p; |
|
|
p.name = (char *) name; |
p.name = (char *) name; |
return (SPLAY_FIND(options_tree, &oo->tree, &p)); |
return (RB_FIND(options_tree, &oo->tree, &p)); |
} |
} |
|
|
struct options_entry * |
struct options_entry * |
|
|
struct options_entry *o, p; |
struct options_entry *o, p; |
|
|
p.name = (char *) name; |
p.name = (char *) name; |
o = SPLAY_FIND(options_tree, &oo->tree, &p); |
o = RB_FIND(options_tree, &oo->tree, &p); |
while (o == NULL) { |
while (o == NULL) { |
oo = oo->parent; |
oo = oo->parent; |
if (oo == NULL) |
if (oo == NULL) |
break; |
break; |
o = SPLAY_FIND(options_tree, &oo->tree, &p); |
o = RB_FIND(options_tree, &oo->tree, &p); |
} |
} |
return (o); |
return (o); |
} |
} |
|
|
if ((o = options_find1(oo, name)) == NULL) |
if ((o = options_find1(oo, name)) == NULL) |
return; |
return; |
|
|
SPLAY_REMOVE(options_tree, &oo->tree, o); |
RB_REMOVE(options_tree, &oo->tree, o); |
xfree(o->name); |
xfree(o->name); |
if (o->type == OPTIONS_STRING) |
if (o->type == OPTIONS_STRING) |
xfree(o->str); |
xfree(o->str); |
|
|
if ((o = options_find1(oo, name)) == NULL) { |
if ((o = options_find1(oo, name)) == NULL) { |
o = xmalloc(sizeof *o); |
o = xmalloc(sizeof *o); |
o->name = xstrdup(name); |
o->name = xstrdup(name); |
SPLAY_INSERT(options_tree, &oo->tree, o); |
RB_INSERT(options_tree, &oo->tree, o); |
} else if (o->type == OPTIONS_STRING) |
} else if (o->type == OPTIONS_STRING) |
xfree(o->str); |
xfree(o->str); |
|
|
|
|
if ((o = options_find1(oo, name)) == NULL) { |
if ((o = options_find1(oo, name)) == NULL) { |
o = xmalloc(sizeof *o); |
o = xmalloc(sizeof *o); |
o->name = xstrdup(name); |
o->name = xstrdup(name); |
SPLAY_INSERT(options_tree, &oo->tree, o); |
RB_INSERT(options_tree, &oo->tree, o); |
} else if (o->type == OPTIONS_STRING) |
} else if (o->type == OPTIONS_STRING) |
xfree(o->str); |
xfree(o->str); |
|
|