mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-19 03:20:14 +00:00
moved drop specialization up
This commit is contained in:
parent
31cae64570
commit
ec731443c4
11 changed files with 581 additions and 84 deletions
|
@ -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
|
||||
"#
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue