File tree 4 files changed +25
-13
lines changed
containers-tests/benchmarks
4 files changed +25
-13
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,9 @@ main = do
79
79
whnf (uncurry M. withoutKeys) (m_random, s_random2)
80
80
, bench " restrictKeys:random" $ -- large keys, no overlap
81
81
whnf (uncurry M. restrictKeys) (m_random, s_random2)
82
+ , bench " size" $ whnf M. size m
83
+ , bench " compareSize:2" $ whnf (flip M. compareSize 2 ) m
84
+ , bench " compareSize:n" $ whnf (flip M. compareSize bound) m
82
85
, bgroup " folds" $ foldBenchmarks M. foldr M. foldl M. foldr' M. foldl' foldMap m
83
86
, bgroup " folds with key" $
84
87
foldWithKeyBenchmarks M. foldrWithKey M. foldlWithKey M. foldrWithKey' M. foldlWithKey' M. foldMapWithKey m
Original file line number Diff line number Diff line change @@ -72,6 +72,12 @@ main = do
72
72
, bench " eq" $ whnf (\ s' -> s' == s') s -- worst case, compares everything
73
73
, bench " compare:dense" $ whnf (\ s' -> compare s' s') s -- worst case, compares everything
74
74
, bench " compare:sparse" $ whnf (\ s' -> compare s' s') s_sparse -- worst case, compares everything
75
+ , bench " size" $ whnf IS. size s
76
+ , bench " size:sparse" $ whnf IS. size s_sparse
77
+ , bench " compareSize:2" $ whnf (flip IS. compareSize 2 ) s
78
+ , bench " compareSize:sparse:2" $ whnf (flip IS. compareSize 2 ) s_sparse
79
+ , bench " compareSize:n" $ whnf (flip IS. compareSize bound) s
80
+ , bench " compareSize:sparse:n" $ whnf (flip IS. compareSize bound) s_sparse
75
81
, bgroup " folds:dense" $ foldBenchmarks IS. foldr IS. foldl IS. foldr' IS. foldl' IS. foldMap s
76
82
, bgroup " folds:sparse" $ foldBenchmarks IS. foldr IS. foldl IS. foldr' IS. foldl' IS. foldMap s_sparse
77
83
]
Original file line number Diff line number Diff line change @@ -598,16 +598,17 @@ size = go 0
598
598
--
599
599
-- @since FIXME
600
600
compareSize :: IntMap a -> Int -> Ordering
601
- compareSize ! _ c0 | c0 < 0 = GT
602
601
compareSize Nil c0 = compare 0 c0
603
- compareSize t c0 = compare 0 (go t c0)
602
+ compareSize _ c0 | c0 <= 0 = GT
603
+ compareSize t c0 = compare 0 (go t (c0 - 1 ))
604
604
where
605
+ go (Bin _ _ _) 0 = - 1
605
606
go (Bin _ l r) c
606
- | c' <= 0 = - 1
607
+ | c' < 0 = c'
607
608
| otherwise = go r c'
608
609
where
609
- c' = go l c
610
- go _ c = c - 1 -- Must be Tip (invariant)
610
+ c' = go l (c - 1 )
611
+ go _ c = c
611
612
612
613
-- | \(O(\min(n,W))\). Is the key a member of the map?
613
614
--
Original file line number Diff line number Diff line change @@ -377,16 +377,18 @@ size = go 0
377
377
--
378
378
-- @since FIXME
379
379
compareSize :: IntSet -> Int -> Ordering
380
- compareSize ! _ c0 | c0 < 0 = GT
381
- compareSize t c0 = compare 0 (go t c0)
380
+ compareSize Nil c0 = compare 0 c0
381
+ compareSize _ c0 | c0 <= 0 = GT
382
+ compareSize t c0 = compare 0 (go t (c0 - 1 ))
382
383
where
384
+ go (Bin _ _ _) 0 = - 1
383
385
go (Bin _ l r) c
384
- | c' <= 0 = - 1
385
- | otherwise = go r c'
386
- where
387
- c' = go l c
388
- go (Tip _ bm) c = c - popCount bm
389
- go Nil c = c
386
+ | c' < 0 = c'
387
+ | otherwise = go r c'
388
+ where
389
+ c' = go l (c - 1 )
390
+ go (Tip _ bm) c = c + 1 - popCount bm
391
+ go Nil ! _ = error " compareSize.go: Nil "
390
392
391
393
-- | \(O(\min(n,W))\). Is the value a member of the set?
392
394
You can’t perform that action at this time.
0 commit comments