uncomment more of rbtree

This commit is contained in:
Folkert 2020-11-12 00:34:35 +01:00
parent 55b26277ca
commit eaf94f2cfc
2 changed files with 35 additions and 24 deletions

View File

@ -362,7 +362,7 @@ pub fn constrain_expr(
vars.push(closure_ext_var);
vars.push(*fn_var);
let body_type = NoExpectation(return_type.clone());
let body_type = NoExpectation(return_type);
let ret_constraint =
constrain_expr(env, loc_body_expr.region, &loc_body_expr.value, body_type);

View File

@ -1,4 +1,4 @@
interface RBTree exposes [ Dict, empty, size, singleton ] imports []
interface RBTree exposes [ Dict, empty, size, singleton, isEmpty, insert, remove, update ] imports []
# The color of a node. Leaves are considered Black.
NodeColor : [ Red, Black ]
@ -147,6 +147,8 @@ removeHelp = \targetKey, dict ->
removeHelpPrepEQGT : Key k, Dict (Key k) v, NodeColor, (Key k), v, Dict (Key k) v, Dict (Key k) v -> Dict (Key k) v
removeHelpPrepEQGT = \_, dict, color, key, value, left, right ->
when left is
@ -171,6 +173,7 @@ removeHelpPrepEQGT = \_, dict, color, key, value, left, right ->
# When we find the node we are looking for, we can remove by replacing the key-value
# pair with the key-value pair of the left-most node on the right side (the closest pair).
removeHelpEQGT : Key k, Dict (Key k) v -> Dict (Key k) v
@ -192,25 +195,28 @@ removeHelpEQGT = \targetKey, dict ->
getMin : Dict k v -> Dict k v
getMin = \dict ->
when dict is
# Node _ _ _ ((Node _ _ _ _ _) as left) _ ->
Node _ _ _ left _ ->
when left is
when left is
Node _ _ _ _ _ -> getMin left
_ -> dict
_ ->
dict
moveRedLeft : Dict k v -> Dict k v
moveRedLeft = \dict ->
when dict is
# Node clr k v (Node lClr lK lV lLeft lRight) (Node rClr rK rV ((Node Red rlK rlV rlL rlR) as rLeft) rRight) ->
Node clr k v (Node lClr lK lV lLeft lRight) (Node rClr rK rV rLeft rRight) ->
when rList is
Node Red rlK rlV rlL rlR ->
# Node clr k v (Node lClr lK lV lLeft lRight) (Node rClr rK rV rLeft rRight) ->
Node clr k v (Node _ lK lV lLeft lRight) (Node _ rK rV rLeft rRight) ->
when rLeft is
Node Red rlK rlV rlL rlR ->
Node
Red
rlK
@ -218,7 +224,7 @@ moveRedLeft = \dict ->
(Node Black k v (Node Red lK lV lLeft lRight) rlL)
(Node Black rK rV rlR rRight)
_ ->
_ ->
when clr is
Black ->
Node
@ -274,30 +280,34 @@ moveRedRight = \dict ->
removeMin : Dict k v -> Dict k v
removeMin = \dict ->
when dict is
Node color key value ((Node lColor _ _ lLeft _) as left) right ->
when lColor is
Black ->
when lLeft is
Node Red _ _ _ _ ->
Node color key value (removeMin left) right
Node color key value left right ->
when left is
Node lColor _ _ lLeft _ ->
when lColor is
Black ->
when lLeft is
Node Red _ _ _ _ ->
Node color key value (removeMin left) right
_ ->
when moveRedLeft dict is
Node nColor nKey nValue nLeft nRight ->
balance nColor nKey nValue (removeMin nLeft) nRight
Empty ->
Empty
_ ->
Node color key value (removeMin left) right
_ ->
when moveRedLeft dict is
Node nColor nKey nValue nLeft nRight ->
balance nColor nKey nValue (removeMin nLeft) nRight
Empty ->
Empty
_ ->
Node color key value (removeMin left) right
Empty
_ ->
Empty
# Update the value of a dictionary for a specific key with a given function.
update : Key k, (Maybe v, Maybe v), Dict (Key k) v -> Dict (Key k) v
update : Key k, (Maybe v -> Maybe v), Dict (Key k) v -> Dict (Key k) v
update = \targetKey, alter, dictionary ->
when alter (get targetKey dictionary) is
Just value ->
@ -305,3 +315,4 @@ update = \targetKey, alter, dictionary ->
Nothing ->
remove targetKey dictionary