39 TestItem self = malloc (
sizeof *self);
41 self->key = strdup (str);
55cmp_fn (
const void*,
const void*);
67fcmp_fn (
const void*,
const void*);
83 static char* sp =
" ";
87 fprintf (fh,
"%s ...\n", sp);
94 fprintf (fh,
"%s%p '%s'\n", sp+40-level,
node, ((TestItem)
node)->
key);
95 if (
node->left) fprintf (fh,
"%sleft %p '%s'\n", sp+40-level,
node->left, ((TestItem)
node->left)->key);
98 if (
node->right) fprintf (fh,
"%sright %p '%s'\n", sp+40-level,
node->right, ((TestItem)
node->right)->key);
110 fprintf (dest,
"root %p '%s'\n", self->tree, self->tree?((TestItem)self->tree)->key:
"EMPTY");
112 fprintf (dest,
"\n");
124 fprintf (fh,
"\t\"%p:%s\":sw -> \"%p:%s\":ne;\n",
128 ((TestItem)
node->left)->key);
132 fprintf (fh,
"\t\"%p:%s\":se -> \"%p:%s\":nw;\n",
136 ((TestItem)
node->right)->key);
151 if (!cnt) cnt = (
time(
NULL) % 1000) * 100;
154 sprintf(
cmd,
"dot -Tps >/var/tmp/dbg%d.ps; gv /var/tmp/dbg%d.ps",cnt,cnt);
155 FILE * graph = popen(
cmd,
"w");
157 fprintf(graph,
"digraph \"%s\" { center=true; size=\"6,6\"; node [color=lightblue2, style=filled];",
"psplay");
160 fprintf(graph,
"\t\"root\":s -> \"%p:%s\":n;\n",
161 self->tree, self->tree?((TestItem)self->tree)->key:
"EMPTY");
192 int end = atoi (argv[2]);
196 for (
int i = 1; i <= end; ++i)
198 sprintf (
key,
"%d", i);
199 ECHO (
"insert %s",
key);
206 for (
int i = 1; i <= end; ++i)
208 sprintf (
key,
"%d", i);
209 ECHO (
"insert %s",
key);
213 for (
int i = end; i; --i)
215 sprintf (
key,
"%d", i);
216 ECHO (
"insert %s",
key);
243 TestItem f = (TestItem)
psplay_find (&splay_tree,
"baz", 100);
245 printf (
"found %p (%.4s)\n", &f->node, f->key);
248 f = (TestItem)
psplay_find (&splay_tree,
"test", 100);
250 printf (
"found %p (%.4s)\n", &f->node, f->key);
253 f = (TestItem)
psplay_find (&splay_tree,
"test", 100);
255 printf (
"found %p (%.4s)\n", &f->node, f->key);
258 f = (TestItem)
psplay_find (&splay_tree,
"foo", 100);
260 printf (
"found %p (%.4s)\n", &f->node, f->key);
273 printf (
"destroying\n");
296 int end = atoi (argv[2]);
300 for (
int i = 1; i <= end; ++i)
302 sprintf (
key,
"%d", i);
303 ECHO (
"insert %s",
key);
307 for (
int i = end/2; i <= end; ++i)
310 sprintf (
key,
"%d", i);
325 int end = atoi (argv[2]);
329 for (
int i = 1; i <= end; ++i)
331 sprintf (
key,
"%d", i );
350 int end = atoi (argv[2]);
354 for (
int i = 1; i <= end; ++i)
356 sprintf (
key,
"%d", i);
410 return strcmp (a, b);
419 return ((TestItem)
node)->key;
435 return strcmp (a, b);
441 return ((TestItem)
node)->key;
void psplay_delete(PSplay self)
Delete a splay tree Frees all elements and associated resources of a splay tree and then itseld.
int psplay_walk(PSplay self, PSplaynode node, psplay_action_fn action, int level, void *data)
Start a tree traversal.
PSplay psplay_init(PSplay self, psplay_cmp_fn cmp, psplay_key_fn key, psplay_delete_fn del)
Initialize a splay tree.
PSplay psplay_destroy(PSplay self)
Destroy a splay tree Frees all elements and associated resources of a splay tree.
PSplaynode psplay_insert(PSplay self, PSplaynode node, int splayfactor)
Insert a element into a splay tree.
const psplay_delete_fn PSPLAY_CONT
PSplaynode psplaynode_init(PSplaynode self)
Initialise a splay tree node The user has to place this nodes within his datastructure and must Initi...
PSplaynode psplay_remove(PSplay self, PSplaynode node)
Remove a node from a splay tree.
void psplay_dump(PSplay self, FILE *dest)
PSplaynode psplay_find(PSplay self, const void *key, int splayfactor)
Find a element in a splay tree.
PSplaynode psplay_remove_key(PSplay self, void *key)
Remove a node by key from a splay tree.
Probabilistic splay tree.
void(* psplay_delete_fn)(PSplaynode node)
Destructor for user defined data Called when an element got removed from a splay tree.
psplay_delete_fn testitem_graphvizprint_node(PSplaynode node, const enum psplay_order_enum which, int level, void *data)
static const void * key_fn(const PSplaynode)
void testitem_graphvizdump(PSplay self, FILE *dest)
TestItem testitem_new(const char *str)
static void delete_fn(PSplaynode)
static const void * fkey_fn(const PSplaynode)
static void fdelete_fn(PSplaynode)
static int cmp_fn(const void *, const void *)
void testitem_delete(TestItem self)
void testitem_dump(PSplay self, FILE *dest)
psplay_delete_fn testitem_print_node(PSplaynode node, const enum psplay_order_enum which, int level, void *data)
static int fcmp_fn(const void *, const void *)
Helpers and support macros for defining test executables in C.