ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change
on this file since 5f53cc3 was
fd54fef,
checked in by Michael Brooks <mlbrooks@…>, 4 years ago
|
Converting the project to use the new syntax for otype, dtype and ttytpe.
Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[6e3ae00] | 1 | #include "avl.h" |
---|
| 2 | // #include "cwrap.h" |
---|
[73abe95] | 3 | #include <stdlib.hfa> |
---|
[6e3ae00] | 4 | |
---|
[fd54fef] | 5 | forall(K | Comparable(K), V) |
---|
[2afec66] | 6 | void ?{}(tree(K, V) &t, K key, V value){ |
---|
| 7 | (t.key) { key }; |
---|
| 8 | (t.value) { value }; |
---|
| 9 | t.parent = NULL; |
---|
| 10 | t.left = NULL; |
---|
| 11 | t.right = NULL; |
---|
| 12 | t.balance = 0; |
---|
[6e3ae00] | 13 | } |
---|
| 14 | |
---|
[fd54fef] | 15 | forall(K| Comparable(K), V) |
---|
[2afec66] | 16 | void ^?{}(tree(K, V) & t){ |
---|
| 17 | delete(t.left); |
---|
| 18 | delete(t.right); |
---|
| 19 | ^(t.key){}; |
---|
| 20 | ^(t.value){}; |
---|
[6e3ae00] | 21 | } |
---|
| 22 | |
---|
[fd54fef] | 23 | forall(K | Comparable(K), V) |
---|
[6e3ae00] | 24 | tree(K, V) * create(K key, V value) { |
---|
| 25 | // infinite loop trying to resolve ... t = malloc(); |
---|
[b81fd95] | 26 | tree(K, V) * t = ( tree(K, V) * ) malloc(sizeof(tree(K,V))); |
---|
[2afec66] | 27 | (*t){ key, value }; |
---|
[6e3ae00] | 28 | return t; |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | // // Helper function to print trees |
---|
| 32 | // forall(otype K | Comparable(K), otype V) |
---|
| 33 | // void printTree(tree * t, int level){ |
---|
| 34 | // if (empty(t)){ |
---|
| 35 | // return; |
---|
| 36 | // } |
---|
| 37 | |
---|
| 38 | // printTree(t->left, level+1); |
---|
| 39 | // printf("key: %d, value: %s, level: %d\n", t->key, t->value, level); |
---|
| 40 | // printTree(t->right, level+1); |
---|
| 41 | // } |
---|
| 42 | |
---|
| 43 | // // inorder traversal of t |
---|
| 44 | // // prints each key, followed by the value |
---|
| 45 | // forall(otype K | Comparable(K), otype V) |
---|
| 46 | // void printTree(tree(K, V) * t){ |
---|
| 47 | // printTree(t, 0); |
---|
| 48 | // } |
---|
Note: See
TracBrowser
for help on using the repository browser.