ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        ctor
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        gc_noraii
        jacob/cs343-translation
        jenkins-sandbox
        memory
        new-ast
        new-ast-unique-expr
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        resolv-new
        with_gc
      
      
        
          | Last change
 on this file since b67dc146 was             6e3ae00, checked in by Rob Schluntz <rschlunt@…>, 9 years ago | 
        
          | 
added avl_test to regression suite and changed runTests.sh to use make -j 8
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.1 KB | 
      
      
| Rev | Line |  | 
|---|
| [6e3ae00] | 1 | #include "avl.h" | 
|---|
|  | 2 | // #include "cwrap.h" | 
|---|
|  | 3 |  | 
|---|
|  | 4 | extern "C" { | 
|---|
|  | 5 | void * malloc(long int); | 
|---|
|  | 6 | } | 
|---|
|  | 7 |  | 
|---|
|  | 8 | forall(otype K | Comparable(K), otype V) | 
|---|
|  | 9 | void ?{}(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 |  | 
|---|
|  | 18 | forall(otype K | Comparable(K), otype V) | 
|---|
|  | 19 | void ^?{}(tree(K, V) * t){ | 
|---|
|  | 20 | delete(t->left); | 
|---|
|  | 21 | delete(t->right); | 
|---|
|  | 22 | ^(&t->key){}; | 
|---|
|  | 23 | ^(&t->value){}; | 
|---|
|  | 24 | } | 
|---|
|  | 25 |  | 
|---|
|  | 26 | forall(otype K | Comparable(K), otype V) | 
|---|
|  | 27 | tree(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.