source: src/tests/avltree/avl_test.c @ 55f5c59

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 55f5c59 was 142cf5d, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

change type of string literal from char[] to const char[]

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