mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
uncomment more of rbtree
This commit is contained in:
parent
55b26277ca
commit
eaf94f2cfc
2 changed files with 35 additions and 24 deletions
|
@ -362,7 +362,7 @@ pub fn constrain_expr(
|
||||||
vars.push(closure_ext_var);
|
vars.push(closure_ext_var);
|
||||||
vars.push(*fn_var);
|
vars.push(*fn_var);
|
||||||
|
|
||||||
let body_type = NoExpectation(return_type.clone());
|
let body_type = NoExpectation(return_type);
|
||||||
let ret_constraint =
|
let ret_constraint =
|
||||||
constrain_expr(env, loc_body_expr.region, &loc_body_expr.value, body_type);
|
constrain_expr(env, loc_body_expr.region, &loc_body_expr.value, body_type);
|
||||||
|
|
||||||
|
|
|
@ -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.
|
# The color of a node. Leaves are considered Black.
|
||||||
NodeColor : [ Red, 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 : 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 ->
|
removeHelpPrepEQGT = \_, dict, color, key, value, left, right ->
|
||||||
when left is
|
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
|
# 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).
|
# 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
|
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 k v -> Dict k v
|
||||||
getMin = \dict ->
|
getMin = \dict ->
|
||||||
when dict is
|
when dict is
|
||||||
|
@ -204,12 +208,14 @@ getMin = \dict ->
|
||||||
_ ->
|
_ ->
|
||||||
dict
|
dict
|
||||||
|
|
||||||
|
|
||||||
moveRedLeft : Dict k v -> Dict k v
|
moveRedLeft : Dict k v -> Dict k v
|
||||||
moveRedLeft = \dict ->
|
moveRedLeft = \dict ->
|
||||||
when dict is
|
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 ((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) ->
|
# Node clr k v (Node lClr lK lV lLeft lRight) (Node rClr rK rV rLeft rRight) ->
|
||||||
when rList is
|
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 rlV rlL rlR ->
|
||||||
Node
|
Node
|
||||||
Red
|
Red
|
||||||
|
@ -274,7 +280,9 @@ moveRedRight = \dict ->
|
||||||
removeMin : Dict k v -> Dict k v
|
removeMin : Dict k v -> Dict k v
|
||||||
removeMin = \dict ->
|
removeMin = \dict ->
|
||||||
when dict is
|
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
|
when lColor is
|
||||||
Black ->
|
Black ->
|
||||||
when lLeft is
|
when lLeft is
|
||||||
|
@ -294,10 +302,12 @@ removeMin = \dict ->
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
Empty
|
Empty
|
||||||
|
_ ->
|
||||||
|
Empty
|
||||||
|
|
||||||
|
|
||||||
# Update the value of a dictionary for a specific key with a given function.
|
# 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 ->
|
update = \targetKey, alter, dictionary ->
|
||||||
when alter (get targetKey dictionary) is
|
when alter (get targetKey dictionary) is
|
||||||
Just value ->
|
Just value ->
|
||||||
|
@ -305,3 +315,4 @@ update = \targetKey, alter, dictionary ->
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
remove targetKey dictionary
|
remove targetKey dictionary
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue