HMap 0.9 → 0.91
raw patch · 3 files changed
+46/−12 lines, 3 filesdep +unordered-containersdep −containersdep ~base
Dependencies added: unordered-containers
Dependencies removed: containers
Dependency ranges changed: base
Files
- ChangeLog +7/−0
- Data/HMap.hs +34/−9
- HMap.cabal +5/−3
+ ChangeLog view
@@ -0,0 +1,7 @@+0.91 : Replaced Data.Map with Hashmap for speed.++0.902 : Support for top level scoped keys++0.901: Improved cabal file++0.9 : Initial version
Data/HMap.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE RankNTypes, GADTs, CPP #-} +{-# LANGUAGE RankNTypes, GADTs, CPP, EmptyDataDecls #-} ----------------------------------------------------------------------------- -- | -- Module : Data.HMap@@ -41,25 +41,34 @@ -- > Edsger: salary=4450.0, female=False -- > Ada: salary=5000.0, female=True ----- The module differes from "HeteroMap.Map" in the following ways:+-- This module differs from hackage package @hetero-map@ in the following ways: -- -- * Lookup, insertion and updates are /O(log n)/ when using this module,--- whereas they are /O(n)/ when using "HeteroMap.Map"+-- whereas they are /O(n)/ when using @hetero-map@. -- -- * With this module we cannot statically ensure that a Heterogenous map -- has a some key (i.e. (!) might throw error, like in "Data.Map").--- With "HeteroMap.Map" it is possible to statically rule out +-- With @hetero-map@ it is possible to statically rule out -- such errors. -- -- * The interface of this module is more similar to "Data.Map" --+-- This module differs from @stable-maps@ in the following ways:+-- +-- * Key can be created safely without using the IO monad.+--+-- * The interface is more uniform and implements more of the+-- "Data.Map" interface.+--+-- -- Since many function names (but not the type name) clash with -- "Prelude" names, this module is usually imported @qualified@, e.g. -- -- > import Data.HMap (HMap) -- > import qualified Data.HMap as HMap ----- This module uses "Data.Map" as a backend.+-- This module uses "Data.Map" as a backend. Every function from "Data.Map"+-- that makes sense in a heterogenous setting has been implemented. -- -- Note that the implementation is /left-biased/ -- the elements of a -- first argument are always preferred to the second, for example in@@ -67,6 +76,7 @@ -- -- Operation comments contain the operation time complexity in -- the Big-O notation <http://en.wikipedia.org/wiki/Big_O_notation>.+-- ----------------------------------------------------------------------------- @@ -78,7 +88,8 @@ -- * Keys , Key , withKey-+ , T+ , createKey -- * Operators , (!), (\\) @@ -121,8 +132,10 @@ import Unsafe.Coerce import Data.Unique import System.IO.Unsafe-import Data.Map(Map)-import qualified Data.Map as M+import Data.Hashable+import Data.HashMap.Lazy(HashMap)++import qualified Data.HashMap.Lazy as M import Data.Maybe(fromJust) @@ -132,8 +145,11 @@ --------------------------------------------------------------------} -- | The HMap type. It's constructor is not exported for safety. -newtype HMap = HMap (Map Unique HideType) +instance Hashable Unique where+ hashWithSalt n u = n + hashUnique u +newtype HMap = HMap (HashMap Unique HideType) + {-------------------------------------------------------------------- Keys --------------------------------------------------------------------}@@ -142,6 +158,8 @@ data HideType where HideType :: a -> HideType ++ unsafeFromHideType :: HideType -> a unsafeFromHideType (HideType x) = unsafeCoerce x @@ -154,6 +172,13 @@ withKey :: (forall x. Key x a -> b) -> b withKey f = f $ Key $ unsafePerformIO newUnique++-- | The scope of top-level keys.+data T ++-- | /O(1)/. Create a new top-level key.+createKey :: IO (Key T a)+createKey = fmap Key newUnique {-------------------------------------------------------------------- Operators
HMap.cabal view
@@ -1,7 +1,7 @@ Name: HMap-Version: 0.9+Version: 0.91 Synopsis: Fast heterogeneous maps.-Description: Fast heterogeneous maps based on Data.Map.+Description: Fast heterogeneous maps based on Hashmaps. License: BSD3 License-file: LICENSE Author: Atze van der Ploeg@@ -9,9 +9,11 @@ Homepage: https://github.com/atzeus/HMap Build-Type: Simple Cabal-Version: >=1.6+Data-files: ChangeLog Category: Data, Data Structures+Tested-With: GHC==7.6.3 Library- Build-Depends: base >= 2 && <= 4, containers >= 0.1.0.0+ Build-Depends: base >= 2 && <= 6, unordered-containers >= 0.2 Exposed-modules: Data.HMap Extensions: RankNTypes, GADTs, CPP