AVL tree: Difference between revisions
→Persistent, non-linear trees
Line 2,393:
| NIL => ()
| CONS _ => ()
(* An implementation of avl_t$compare for keys of type ‘int’. *)▼
implement▼
avl_t$compare<int> (u, v) =▼
if u < v then▼
~1▼
else if u > v then▼
1▼
else▼
0▼
(* An implementation of avl_t_pretty_print$key_and_data for keys of▼
type ‘int’ and values of type ‘double’. *)▼
implement▼
avl_t_pretty_print$key_and_data<int><double> (key, data) =▼
print! ("(", key, ", ", data, ")")▼
fn {}
Line 2,821 ⟶ 2,805:
(avl_t (key_t, data_t, sz), fixbal_t) =
if fixbal then
balance_L__ p
else
(p, F)
Line 2,832 ⟶ 2,816:
(avl_t (key_t, data_t, sz), fixbal_t) =
if fixbal then
balance_R__ p
else
(p, F)
Line 3,307 ⟶ 3,291:
Assuming you are using Boehm GC, compile this source file with
patscc -O2 -DATS_MEMALLOC_GCBDW avl_trees-postiats.dats -lgc
and run it with
Line 3,324 ⟶ 3,308:
}
%}
▲(* An implementation of avl_t$compare for keys of type ‘int’. *)
▲implement
▲avl_t$compare<int> (u, v) =
▲ if u < v then
▲ ~1
▲ else if u > v then
▲ 1
▲ else
▲ 0
▲(* An implementation of avl_t_pretty_print$key_and_data for keys of
▲ type ‘int’ and values of type ‘double’. *)
▲implement
▲avl_t_pretty_print$key_and_data<int><double> (key, data) =
▲ print! ("(", key, ", ", data, ")")
implement
Line 3,723:
(You could compile with ‘-DATS_MEMALLOC_LIBC’ and leave out the ‘-lgc’. Then the heap memory used will simply be recovered only when the program ends.)
<pre>$ patscc -O2 -DATS_MEMALLOC_GCBDW avl_trees-postiats.dats -lgc
----------------------------------------------------
|