Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Fixes for 0.6.1 #17

Merged
merged 2 commits into from
Nov 18, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/Data/Map.purs
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,25 @@ delete = down []
where
down :: forall k v. (P.Ord k) => [TreeContext k v] -> k -> Map k v -> Map k v
down ctx _ Leaf = fromZipper ctx Leaf
down ctx k (Two Leaf k1 _ Leaf) | k P.== k1 = up ctx Leaf
down ctx k (Two left k1 _ right) | k P.== k1 =
let max = maxNode left
in removeMaxNode (TwoLeft max.key max.value right P.: ctx) left
down ctx k (Two left k1 v1 right) | k P.< k1 = down (TwoLeft k1 v1 right P.: ctx) k left
down ctx k (Two left k1 v1 right) = down (TwoRight left k1 v1 P.: ctx) k right
down ctx k (Three Leaf k1 _ Leaf k2 v2 Leaf) | k P.== k1 = fromZipper ctx (Two Leaf k2 v2 Leaf)
down ctx k (Three Leaf k1 v1 Leaf k2 _ Leaf) | k P.== k2 = fromZipper ctx (Two Leaf k1 v1 Leaf)
down ctx k (Three left k1 _ mid k2 v2 right) | k P.== k1 =
let max = maxNode left
in removeMaxNode (ThreeLeft max.key max.value mid k2 v2 right P.: ctx) left
down ctx k (Three left k1 v1 mid k2 _ right) | k P.== k2 =
let max = maxNode mid
in removeMaxNode (ThreeMiddle left k1 v1 max.key max.value right P.: ctx) mid
down ctx k (Three left k1 v1 mid k2 v2 right) | k P.< k1 = down (ThreeLeft k1 v1 mid k2 v2 right P.: ctx) k left
down ctx k (Three left k1 v1 mid k2 v2 right) | k1 P.< k P.&& k P.< k2 = down (ThreeMiddle left k1 v1 k2 v2 right P.: ctx) k mid
down ctx k (Three left k1 v1 mid k2 v2 right) = down (ThreeRight left k1 v1 mid k2 v2 P.: ctx) k right
down ctx k (Two Leaf k1 _ Leaf)
| k P.== k1 = up ctx Leaf
down ctx k (Two left k1 v1 right)
| k P.== k1 = let max = maxNode left
in removeMaxNode (TwoLeft max.key max.value right P.: ctx) left
| k P.< k1 = down (TwoLeft k1 v1 right P.: ctx) k left
| P.otherwise = down (TwoRight left k1 v1 P.: ctx) k right
down ctx k (Three Leaf k1 _ Leaf k2 v2 Leaf)
| k P.== k1 = fromZipper ctx (Two Leaf k2 v2 Leaf)
down ctx k (Three Leaf k1 v1 Leaf k2 _ Leaf)
| k P.== k2 = fromZipper ctx (Two Leaf k1 v1 Leaf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be combined with the previous one right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I see how...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

down ctx k (Three Leaf k1 v1 Leaf k2 v2 Leaf)
  | k P.== k1 = fromZipper ctx (Two Leaf k2 v2 Leaf)
  | k P.== k2 = fromZipper ctx (Two Leaf k1 v1 Leaf)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh.

down ctx k (Three left k1 v1 mid k2 v2 right)
| k P.== k1 = let max = maxNode left
in removeMaxNode (ThreeLeft max.key max.value mid k2 v2 right P.: ctx) left
| k P.== k2 = let max = maxNode mid
in removeMaxNode (ThreeMiddle left k1 v1 max.key max.value right P.: ctx) mid
| k P.< k1 = down (ThreeLeft k1 v1 mid k2 v2 right P.: ctx) k left
| k1 P.< k P.&& k P.< k2 = down (ThreeMiddle left k1 v1 k2 v2 right P.: ctx) k mid
| P.otherwise = down (ThreeRight left k1 v1 mid k2 v2 P.: ctx) k right

up :: forall k v. (P.Ord k) => [TreeContext k v] -> Map k v -> Map k v
up [] tree = tree
Expand Down