2010-11-20 12:29:18 +02:00
|
|
|
/*
|
|
|
|
* rbtest.c - Very basic regression test for red-black trees
|
|
|
|
*
|
|
|
|
* Written 2010 by Werner Almesberger
|
|
|
|
* Copyright 2010 Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-11-20 00:33:05 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "jrb.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-20 00:47:52 +02:00
|
|
|
static int cmp(const void *a, const void *b)
|
2010-11-20 00:33:05 +02:00
|
|
|
{
|
2010-11-20 00:47:52 +02:00
|
|
|
return strcmp(a, b);
|
2010-11-20 00:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define INSERT(key, val) \
|
2010-11-20 00:52:39 +02:00
|
|
|
jrb_insert(tree, key, val, cmp)
|
2010-11-20 00:33:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2010-11-20 01:48:49 +02:00
|
|
|
struct jrb *tree = make_jrb();
|
|
|
|
struct jrb *p;
|
2010-11-20 00:33:05 +02:00
|
|
|
|
|
|
|
INSERT("ab", "have");
|
2010-11-20 01:30:24 +02:00
|
|
|
INSERT("ac", "NOT");
|
2010-11-20 00:33:05 +02:00
|
|
|
INSERT("d", "little");
|
|
|
|
INSERT("c", "this");
|
|
|
|
INSERT("b", "passed");
|
|
|
|
INSERT("e", "regression");
|
|
|
|
INSERT("fa", "test");
|
|
|
|
INSERT("aa", "We");
|
|
|
|
INSERT("ff", "!");
|
|
|
|
|
2010-11-20 01:30:24 +02:00
|
|
|
p = jrb_find(tree, "ac", cmp);
|
|
|
|
jrb_delete_node(p);
|
|
|
|
|
2010-11-20 00:33:05 +02:00
|
|
|
jrb_traverse(p, tree)
|
2010-11-20 00:47:52 +02:00
|
|
|
printf("%s ", (char *) jrb_val(p));
|
2010-11-20 00:33:05 +02:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|