Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/avltree/avl-private.cfa

    rfd54fef r107b01a  
    1111// an AVL tree's height is easy to compute
    1212// just follow path with the larger balance
    13 forall(K | Comparable(K), V)
     13forall(otype K | Comparable(K), otype V)
    1414int height(tree(K, V) * t){
    1515  int helper(tree(K, V) * t, int ht){
     
    2727}
    2828
    29 forall(K | Comparable(K), V)
     29forall(otype K | Comparable(K), otype V)
    3030int calcBalance(tree(K, V) * t){
    3131  int l = height(t->left);
     
    3636
    3737// re-establish the link between parent and child
    38 forall(K | Comparable(K), V)
     38forall(otype K | Comparable(K), otype V)
    3939void relinkToParent(tree(K, V) * t){
    4040  tree(K, V) * parent = t->parent; // FIX ME!!
     
    4949
    5050// rotate left from t
    51 forall(K | Comparable(K), V)
     51forall(otype K | Comparable(K), otype V)
    5252tree(K, V) * rotateLeft(tree(K, V) * t){
    5353  tree(K, V) * newRoot = t->right;
     
    6868
    6969// rotate right from t
    70 forall(K | Comparable(K), V)
     70forall(otype K | Comparable(K), otype V)
    7171tree(K, V) * rotateRight(tree(K, V) * t){
    7272  tree(K, V) * newRoot = t->left;
     
    8787
    8888// balances a node that has balance factor -2 or 2
    89 forall(K | Comparable(K), V)
     89forall(otype K | Comparable(K), otype V)
    9090tree(K, V) * fix(tree(K, V) * t){
    9191  // ensure that t's balance factor is one of
     
    113113
    114114// attempt to fix the tree, if necessary
    115 forall(K | Comparable(K), V)
     115forall(otype K | Comparable(K), otype V)
    116116tree(K, V) * tryFix(tree(K, V) * t){
    117117  int b = calcBalance(t);
     
    126126
    127127// sets parent field of c to be p
    128 forall(K | Comparable(K), V)
     128forall(otype K | Comparable(K), otype V)
    129129void setParent(tree(K, V) * c, tree(K, V) * p){
    130130  if (! empty(c)){
Note: See TracChangeset for help on using the changeset viewer.