This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | `Map k v` represents maps from keys of type `k` to values of type `v`.
Expand Down
Expand Up
@@ -507,7 +507,7 @@ pop k = down Nil
comp = compare
down :: List (TreeContext k v) -> Map k v -> Maybe (Tuple v (Map k v))
down = unsafePartial \ctx m -> case m of
down ctx m = case m of
Leaf -> Nothing
Two left k1 v1 right ->
case right, comp k k1 of
Expand All
@@ -533,7 +533,7 @@ pop k = down Nil
_ , _ , _ -> down (Cons (ThreeRight left k1 v1 mid k2 v2) ctx) right
up :: List (TreeContext k v) -> Map k v -> Map k v
up = unsafePartial \ctxs tree ->
up ctxs tree =
case ctxs of
Nil -> tree
Cons x ctx ->
Expand All
@@ -555,22 +555,25 @@ pop k = down Nil
ThreeMiddle (Three a k1 v1 b k2 v2 c) k3 v3 k4 v4 e, d -> fromZipper ctx (Three (Two a k1 v1 b) k2 v2 (Two c k3 v3 d) k4 v4 e)
ThreeMiddle a k1 v1 k2 v2 (Three c k3 v3 d k4 v4 e), b -> fromZipper ctx (Three a k1 v1 (Two b k2 v2 c) k3 v3 (Two d k4 v4 e))
ThreeRight a k1 v1 (Three b k2 v2 c k3 v3 d) k4 v4, e -> fromZipper ctx (Three a k1 v1 (Two b k2 v2 c) k3 v3 (Two d k4 v4 e))
_, _ -> unsafeCrashWith "The impossible happened in partial function `up`."
maxNode :: Map k v -> { key :: k, value :: v }
maxNode = unsafePartial \m -> case m of
maxNode m = case m of
Two _ k' v Leaf -> { key: k', value: v }
Two _ _ _ right -> maxNode right
Three _ _ _ _ k' v Leaf -> { key: k', value: v }
Three _ _ _ _ _ _ right -> maxNode right
_ -> unsafeCrashWith "The impossible happened in partial function `maxNode`."
removeMaxNode :: List (TreeContext k v) -> Map k v -> Map k v
removeMaxNode = unsafePartial \ctx m ->
removeMaxNode ctx m =
case m of
Two Leaf _ _ Leaf -> up ctx Leaf
Two left k' v right -> removeMaxNode (Cons (TwoRight left k' v) ctx) right
Three Leaf k1 v1 Leaf _ _ Leaf -> up (Cons (TwoRight Leaf k1 v1) ctx) Leaf
Three left k1 v1 mid k2 v2 right -> removeMaxNode (Cons (ThreeRight left k1 v1 mid k2 v2) ctx) right
_ -> unsafeCrashWith "The impossible happened in partial function `removeMaxNode`."
-- | Insert the value, delete a value, or update a value for a key in a map
Expand Down
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tweak unsafePartial usages #57
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Tweak unsafePartial usages #57
Filter by extension
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing