Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
|||
processor RedBlackTree
|
||||
data node <{VOID}|{colour: <='black'|='red'>, left: <node>, right: <node>, value: <> VOID}> local
|
||||
@: {};
|
||||
sink insert
|
||||
templates balance
|
||||
when <{colour: <='black'>, left: <{ colour: <='red'> left: <{colour: <='red'>}>}>}>
|
||||
do { colour: 'red',
|
||||
left: { $.left.left..., colour: 'black'},
|
||||
value: $.left.value,
|
||||
right: { $..., left: $.left.right }} !
|
||||
when <{colour: <='black'>, left: <{ colour: <='red'> right: <{colour: <='red'>}>}>}>
|
||||
do { colour: 'red',
|
||||
left: { $.left..., colour: 'black', right: $.left.right.left},
|
||||
value: $.left.right.value,
|
||||
right: { $..., left: $.left.right.right }} !
|
||||
when <{colour: <='black'>, right: <{ colour: <='red'> left: <{colour: <='red'>}>}>}>
|
||||
do { colour: 'red',
|
||||
left: { $..., right: $.right.left.left},
|
||||
value: $.right.left.value,
|
||||
right: { $.right..., colour: 'black', left: $.right.left.right }} !
|
||||
when <{colour: <='black'>, right: <{ colour: <='red'> right: <{colour: <='red'>}>}>}>
|
||||
do { colour: 'red',
|
||||
left: { $..., right: $.right.left},
|
||||
value: $.right.value,
|
||||
right: { $.right.right..., colour: 'black' }} !
|
||||
otherwise $ !
|
||||
end balance
|
||||
templates ins&{into:}
|
||||
when <?($into <´node´ ={}>)> do { colour: 'red', left: {}, value: $, right: {}} !
|
||||
when <..$into.value::raw> do { $into..., left: $ -> ins&{into: $into.left}} -> balance !
|
||||
otherwise { $into..., right: $ -> ins&{into: $into.right}} -> balance !
|
||||
end ins
|
||||
@RedBlackTree: { $ -> ins&{into: $@RedBlackTree} ..., colour: 'black'};
|
||||
end insert
|
||||
source toString
|
||||
'$@RedBlackTree;' !
|
||||
end toString
|
||||
end RedBlackTree
|
||||
|
||||
def tree: $RedBlackTree;
|
||||
1..5 -> \('$tree::toString;$#10;' -> !OUT::write $ -> !tree::insert \) -> !VOID
|
||||
$tree::toString -> !OUT::write
|
||||
Loading…
Add table
Add a link
Reference in a new issue