Commit 492e7fd0 authored by Mike Ledger's avatar Mike Ledger
Browse files

faster IntSet.size

parent 9be1604f
......@@ -311,9 +311,11 @@ null _ = False
-- | /O(n)/. Cardinality of the set.
size :: IntSet -> Int
size (Bin _ _ l r) = size l + size r
size (Tip _ bm) = bitcount 0 bm
size Nil = 0
size = go 0
where
go !acc (Bin _ _ l r) = go (go acc l) r
go acc (Tip _ bm) = acc + bitcount 0 bm
go acc Nil = acc
-- | /O(min(n,W))/. Is the value a member of the set?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment