Root/qpkg/rbtest.c

Source at commit 757f19cd7b4e61ff04f1707ccea9fa3b146db220 created 8 years 8 months ago.
By Werner Almesberger, moved m1/torture/ to more specific m1rc3/norruption/
1/*
2 * rbtest.c - Very basic regression test for red-black trees
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdio.h>
15#include <string.h>
16
17#include "jrb.h"
18
19
20
21static int cmp(const void *a, const void *b)
22{
23    return strcmp(a, b);
24}
25
26
27#define INSERT(key, val) \
28    jrb_insert(tree, key, val, cmp)
29
30
31int main(void)
32{
33    struct jrb *tree = make_jrb();
34    struct jrb *p;
35
36    INSERT("ab", "have");
37    INSERT("ac", "NOT");
38    INSERT("d", "little");
39    INSERT("c", "this");
40    INSERT("b", "passed");
41    INSERT("e", "regression");
42    INSERT("fa", "test");
43    INSERT("aa", "We");
44    INSERT("ff", "!");
45
46    p = jrb_find(tree, "ac", cmp);
47    jrb_delete_node(p);
48
49    jrb_traverse(p, tree)
50        printf("%s ", (char *) jrb_val(p));
51    printf("\n");
52
53    return 0;
54}
55

Archive Download this file

Branches:
master



interactive