moved drop specialization up

This commit is contained in:
J.Teeuwissen 2023-05-07 17:55:26 +02:00 committed by Folkert
parent 31cae64570
commit ec731443c4
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
11 changed files with 581 additions and 84 deletions

View file

@ -2955,3 +2955,58 @@ fn binary_tree_fbip() {
"#
)
}
#[mono_test]
fn rb_tree_fbip() {
indoc!(
r#"
app "test" provides [main] to "./platform"
main = Leaf
|> ins 0 0
|> ins 5 1
|> ins 6 2
|> ins 4 3
|> ins 9 4
|> ins 3 5
|> ins 2 6
|> ins 1 7
|> ins 8 8
|> ins 7 9
Color : [Red, Black]
Tree a : [Node Color (Tree a) I32 a (Tree a), Leaf]
ins : Tree a, I32, a -> Tree a
ins = \t, k, v -> when t is
Leaf -> Node Red Leaf k v Leaf
Node Black l kx vx r ->
if k < kx
then when l is
Node Red _ _ _ _ -> when (ins l k v) is
Node _ (Node Red ly ky vy ry) kz vz rz -> Node Red (Node Black ly ky vy ry) kz vz (Node Black rz kx vx r)
Node _ lz kz vz (Node Red ly ky vy ry) -> Node Red (Node Black lz kz vz ly) ky vy (Node Black ry kx vx r)
Node _ ly ky vy ry -> Node Black (Node Red ly ky vy ry) kx vx r
Leaf -> Leaf
_ -> Node Black (ins l k v) kx vx r
else
if k > kx
then when r is
Node Red _ _ _ _ -> when ins r k v is
Node _ (Node Red ly ky vy ry) kz vz rz -> Node Red (Node Black ly ky vy ry) kz vz (Node Black rz kx vx r)
Node _ lz kz vz (Node Red ly ky vy ry) -> Node Red (Node Black lz kz vz ly) ky vy (Node Black ry kx vx r)
Node _ ly ky vy ry -> Node Black (Node Red ly ky vy ry) kx vx r
Leaf -> Leaf
_ -> Node Black l kx vx (ins r k v)
else Node Black l k v r
Node Red l kx vx r ->
if k < kx
then Node Red (ins l k v) kx vx r
else
if k > kx
then Node Red l kx vx (ins r k v)
else Node Red l k v r
"#
)
}