Commit 9be1604f authored by Mike Ledger's avatar Mike Ledger
Browse files

faster IntMap.size

parent f42e9321
......@@ -512,9 +512,11 @@ null _ = False
-- > size (singleton 1 'a') == 1
-- > size (fromList([(1,'a'), (2,'c'), (3,'b')])) == 3
size :: IntMap a -> Int
size (Bin _ _ l r) = size l + size r
size (Tip _ _) = 1
size Nil = 0
size = go 0
where
go !acc (Bin _ _ l r) = go (go acc l) r
go acc (Tip _ _) = 1 + acc
go acc Nil = acc
-- | /O(min(n,W))/. Is the key a member of the map?
--
......
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