unordered-containers 0.1.1.0 → 0.1.2.0
raw patch · 5 files changed
+73/−29 lines, 5 files
Files
- Data/HashMap/Common.hs +3/−2
- Data/HashMap/Lazy.hs +0/−26
- Data/HashMap/Lazy/Internal.hs +48/−0
- Data/HashMap/Strict/Internal.hs +19/−0
- unordered-containers.cabal +3/−1
Data/HashMap/Common.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE BangPatterns, CPP #-}+{-# LANGUAGE BangPatterns, CPP, DeriveDataTypeable #-} -- | Code shared between the lazy and strict versions. @@ -31,6 +31,7 @@ import Data.Bits ((.&.), xor) import qualified Data.Foldable as Foldable import Data.Traversable (Traversable(..))+import Data.Typeable (Typeable) import Data.Word (Word) import Prelude hiding (foldr, map) @@ -49,7 +50,7 @@ {-# UNPACK #-} !Mask !(HashMap k v) !(HashMap k v)- deriving Show+ deriving (Show, Typeable) type Suffix = Int type Mask = Int
Data/HashMap/Lazy.hs view
@@ -312,29 +312,3 @@ elems :: HashMap k v -> [v] elems = List.map snd . toList {-# INLINE elems #-}------------------------------------------------------------------------- Metadata about map behavior---- | /O(n)/ Return the number of hash collisions in this map.-collisions :: HashMap k v -> Int-collisions t = go t 0- where- go (Bin _ _ l r) !sz = go r (go l sz)- go (Tip _ l) !sz- | fl_sz <= 1 = sz- | otherwise = sz + fl_sz- where fl_sz = FL.size l- go Nil !sz = sz---- | /O(n)/ Return histogram of hash collisions in this map.--- Keys are number of entries in bucket, values are number of buckets--- of that size.-collisionHistogram :: HashMap k v -> HashMap Int Int-collisionHistogram t = go t Nil- where- go (Bin _ _ l r) h = go r (go l h)- go (Tip _ l) h = (insert sz $! maybe 1 (1+) (lookup sz h)) h- where sz = FL.size l- go Nil h = h
+ Data/HashMap/Lazy/Internal.hs view
@@ -0,0 +1,48 @@+{-# LANGUAGE BangPatterns #-}++------------------------------------------------------------------------+-- |+-- Module : Data.HashMap.Lazy.Internal+-- Copyright : 2010-2011 Johan Tibell+-- License : BSD-style+-- Maintainer : johan.tibell@gmail.com+-- Stability : provisional+-- Portability : portable+--+-- Semi-public internals.++module Data.HashMap.Lazy.Internal+ ( collisions+ , collisionHistogram+ ) where++import Prelude hiding (lookup)++import qualified Data.FullList.Lazy as FL+import Data.HashMap.Common (HashMap(..))+import Data.HashMap.Lazy (insert, lookup)++-------------------------------------------------------------------+-- Metadata about map behavior++-- | /O(n)/ Return the number of hash collisions in this map.+collisions :: HashMap k v -> Int+collisions t = go t 0+ where+ go (Bin _ _ l r) !sz = go r (go l sz)+ go (Tip _ l) !sz+ | fl_sz <= 1 = sz+ | otherwise = sz + fl_sz+ where fl_sz = FL.size l+ go Nil !sz = sz++-- | /O(n)/ Return histogram of hash collisions in this map.+-- Keys are number of entries in bucket, values are number of buckets+-- of that size.+collisionHistogram :: HashMap k v -> HashMap Int Int+collisionHistogram t = go t Nil+ where+ go (Bin _ _ l r) h = go r (go l h)+ go (Tip _ l) h = (insert sz $! maybe 1 (1+) (lookup sz h)) h+ where sz = FL.size l+ go Nil h = h
+ Data/HashMap/Strict/Internal.hs view
@@ -0,0 +1,19 @@+{-# LANGUAGE BangPatterns #-}++------------------------------------------------------------------------+-- |+-- Module : Data.HashMap.Strict.Internal+-- Copyright : 2010-2011 Johan Tibell+-- License : BSD-style+-- Maintainer : johan.tibell@gmail.com+-- Stability : provisional+-- Portability : portable+--+-- Semi-public internals.++module Data.HashMap.Strict.Internal+ ( collisions+ , collisionHistogram+ ) where++import Data.HashMap.Lazy.Internal
unordered-containers.cabal view
@@ -1,5 +1,5 @@ name: unordered-containers-version: 0.1.1.0+version: 0.1.2.0 synopsis: Efficient hashing-based container types description: Efficient hashing-based container types. The containers have been@@ -37,6 +37,8 @@ Data.FullList.Lazy Data.FullList.Strict Data.HashMap.Common+ Data.HashMap.Lazy.Internal+ Data.HashMap.Strict.Internal ghc-options: -Wall -O2 if impl(ghc >= 6.8)