| [6e3ae00] | 1 | #include "avl.h" | 
|---|
|  | 2 | #include "avl-private.h" | 
|---|
|  | 3 |  | 
|---|
|  | 4 | extern "C" { | 
|---|
|  | 5 | int printf(const char *, ...); | 
|---|
|  | 6 | int strcmp(const char *, const char *); | 
|---|
|  | 7 | } | 
|---|
|  | 8 |  | 
|---|
|  | 9 | int main(){ | 
|---|
|  | 10 | // operations: | 
|---|
|  | 11 | // find(tree(K, V) *, K) | 
|---|
|  | 12 | // int empty(tree(K, V) *); | 
|---|
|  | 13 | // tree(K, V) * insert(tree(K, V) *, K, V); | 
|---|
|  | 14 | // int remove(tree(K, V) **, K); | 
|---|
|  | 15 |  | 
|---|
|  | 16 | // int -> int | 
|---|
|  | 17 | tree(int, int) * imap = create(-1, 0); | 
|---|
|  | 18 | insert(&imap, 12, 13); | 
|---|
|  | 19 | insert(&imap, 2, 3); | 
|---|
|  | 20 | assert( height(imap) == 2 ); | 
|---|
|  | 21 |  | 
|---|
|  | 22 | printf("%d %d %d\n", *find(imap, 2), *find(imap, 12), *find(imap, -1)); | 
|---|
|  | 23 |  | 
|---|
|  | 24 | remove(&imap, -1); | 
|---|
|  | 25 | delete(imap); | 
|---|
|  | 26 |  | 
|---|
|  | 27 | // int -> char * | 
|---|
|  | 28 | tree(int, char *) * smap = create(-1, "baz"); | 
|---|
|  | 29 | insert(&smap, 12, "bar"); | 
|---|
|  | 30 | insert(&smap, 2, "foo"); | 
|---|
|  | 31 | assert( height(smap) == 2 ); | 
|---|
|  | 32 |  | 
|---|
|  | 33 | printf("%s %s %s\n", *find(smap, 2), *find(smap, 12), *find(smap, -1)); | 
|---|
|  | 34 |  | 
|---|
|  | 35 | remove(&smap, -2); | 
|---|
|  | 36 | delete(smap); | 
|---|
|  | 37 |  | 
|---|
|  | 38 | // char* -> char* | 
|---|
|  | 39 | int ?<?(char *a, char *b) { | 
|---|
|  | 40 | return strcmp(a,b) < 0; | 
|---|
|  | 41 | } | 
|---|
|  | 42 | tree(char *, char *) * ssmap = create("queso", "cheese"); | 
|---|
|  | 43 | insert(&ssmap, "foo", "bar"); | 
|---|
|  | 44 | insert(&ssmap, "hello", "world"); | 
|---|
|  | 45 | assert( height(ssmap) == 2 ); | 
|---|
|  | 46 |  | 
|---|
|  | 47 | printf("%s %s %s\n", *find(ssmap, "hello"), *find(ssmap, "foo"), *find(ssmap, "queso")); | 
|---|
|  | 48 |  | 
|---|
|  | 49 | remove(&ssmap, "foo"); | 
|---|
|  | 50 | delete(ssmap); | 
|---|
|  | 51 | } | 
|---|