Skip to content

Commit e0cfb50

Browse files
committed
Merge pull request #116 from treeowl/balanceReplicate
Make applicativeTree aim for safe digits
2 parents a4df7f3 + 1e962fc commit e0cfb50

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Data/Sequence.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -859,17 +859,14 @@ applicativeTree n mSize m = mSize `seq` case n of
859859
4 -> deepA two emptyTree two
860860
5 -> deepA three emptyTree two
861861
6 -> deepA three emptyTree three
862-
7 -> deepA four emptyTree three
863-
8 -> deepA four emptyTree four
864862
_ -> case n `quotRem` 3 of
865863
(q,0) -> deepA three (applicativeTree (q - 2) mSize' n3) three
866-
(q,1) -> deepA four (applicativeTree (q - 2) mSize' n3) three
867-
(q,_) -> deepA four (applicativeTree (q - 2) mSize' n3) four
864+
(q,1) -> deepA two (applicativeTree (q - 1) mSize' n3) two
865+
(q,_) -> deepA three (applicativeTree (q - 1) mSize' n3) two
868866
where
869867
one = fmap One m
870868
two = liftA2 Two m m
871869
three = liftA3 Three m m m
872-
four = liftA3 Four m m m <*> m
873870
deepA = liftA3 (Deep (n * mSize))
874871
mSize' = 3 * mSize
875872
n3 = liftA3 (Node3 mSize') m m m
@@ -2338,7 +2335,7 @@ unstableSortBy cmp (Seq xs) =
23382335
toPQ cmp (\ (Elem x) -> PQueue x Nil) xs
23392336

23402337
-- | fromList2, given a list and its length, constructs a completely
2341-
-- balanced Seq whose elements are that list using the applicativeTree
2338+
-- balanced Seq whose elements are that list using the replicateA
23422339
-- generalization.
23432340
fromList2 :: Int -> [a] -> Seq a
23442341
fromList2 n = execState (replicateA n (State ht))

0 commit comments

Comments
 (0)