source: src/tests/avltree/avl1.c @ 205ee4e

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 205ee4e was 3dcd347a, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

moved some more tests to new test folder

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include "avl.h"
2// #include "cwrap.h"
3
4extern "C" {
5  void * malloc(long int);
6}
7
8forall(otype K | Comparable(K), otype V)
9void ?{}(tree(K, V) *t, K key, V value){
10  (&t->key) { key };
11  (&t->value) { value };
12  t->parent = NULL;
13  t->left = NULL;
14  t->right = NULL;
15  t->balance = 0;
16}
17
18forall(otype K | Comparable(K), otype V)
19void ^?{}(tree(K, V) * t){
20  delete(t->left);
21  delete(t->right);
22  ^(&t->key){};
23  ^(&t->value){};
24}
25
26forall(otype K | Comparable(K), otype V)
27tree(K, V) * create(K key, V value) {
28  // infinite loop trying to resolve ... t = malloc();
29  tree(K, V) * t = malloc(sizeof(tree(K,V)));
30  t { key, value };
31  return t;
32}
33
34// // Helper function to print trees
35// forall(otype K | Comparable(K), otype V)
36// void printTree(tree * t, int level){
37//   if (empty(t)){
38//     return;
39//   }
40
41//   printTree(t->left, level+1);
42//   printf("key: %d, value: %s, level: %d\n", t->key, t->value, level);
43//   printTree(t->right, level+1);
44// }
45
46// // inorder traversal of t
47// // prints each key, followed by the value
48// forall(otype K | Comparable(K), otype V)
49// void printTree(tree(K, V) * t){
50//     printTree(t, 0);
51// }
Note: See TracBrowser for help on using the repository browser.