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,6 +195,7 @@ removeHelpEQGT = \targetKey, dict ->
getMin : Dict k v -> Dict k v
getMin = \dict ->
when dict is
@ -204,12 +208,14 @@ getMin = \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 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
@ -274,7 +280,9 @@ moveRedRight = \dict ->
removeMin : Dict k v -> Dict k v
removeMin = \dict ->
when dict is
Node color key value ((Node lColor _ _ lLeft _) as left) right ->
Node color key value left right ->
when left is
Node lColor _ _ lLeft _ ->
when lColor is
Black ->
when lLeft is
@ -294,10 +302,12 @@ removeMin = \dict ->
_ ->
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