mmsyn2-hashable (empty) → 0.1.0.0
raw patch · 5 files changed
+127/−0 lines, 5 filesdep +basedep +ghc-primdep +hashablesetup-changed
Dependencies added: base, ghc-prim, hashable, hashtables
Files
- CHANGELOG.md +7/−0
- Case/Hashable/Cuckoo.hs +72/−0
- LICENSE +20/−0
- Setup.hs +2/−0
- mmsyn2-hashable.cabal +26/−0
+ CHANGELOG.md view
@@ -0,0 +1,7 @@+# Revision history for mmsyn2-hashable++## 0.1.0.0 -- 2021-10-31++* First version. Released on an unsuspecting world. Forked from the mmsyn2-array-0.2.2.0 +package.+
+ Case/Hashable/Cuckoo.hs view
@@ -0,0 +1,72 @@+-- |+-- Module : Case.Hashable.Cuckoo+-- Copyright : (c) OleksandrZhabenko 2021+-- License : MIT+-- Stability : Experimental+-- Maintainer : olexandr543@yahoo.com+--+-- A library that can be used as a @case ... of@ constuction analogue for the Hashable keys.+-- For the large lists can be more time efficient than CaseBi.Arr.getBFst' analogue. For the lists of 'Int's+-- the benchmarks does not show significant improvements, but it definitely uses more memory if linked statically.+-- If you plan to use it together with the former one, please, use qualified import to avoid names ambiguity.+++{-# LANGUAGE MagicHash, UnboxedTuples #-}++module Case.Hashable.Cuckoo where++import qualified Data.HashTable.ST.Cuckoo as C+import qualified Data.HashTable.Class as H (fromList, fromListWithSizeHint)+import GHC.ST+import GHC.Magic (runRW# )+import Data.Maybe (fromMaybe)+import Data.Hashable (Hashable(..))+import GHC.Arr++getBFstL' :: (Eq k, Hashable k) => v -> [(k, v)] -> k -> v+getBFstL' def pairs key = fromMaybe def .+ (\(ST st_rep) -> case runRW# st_rep of (# _, a #) -> a) . -- Actually is rewritten from the GHC.ST.runST to remove the forall constraint+ lookup2 pairs $ key+{-# INLINE getBFstL' #-}++lookup2 pairs key = H.fromList pairs >>= \ht -> C.lookup ht key+{-# INLINE lookup2 #-}++lookup2Sized n pairs key = H.fromListWithSizeHint n pairs >>= \ht -> C.lookup ht key+{-# INLINE lookup2Sized #-}++lookupL pairs keys = H.fromList pairs >>= \ht -> mapM (C.lookup ht) keys+{-# INLINE lookupL #-}++lookupLSized n pairs keys = H.fromListWithSizeHint n pairs >>= \ht -> mapM (C.lookup ht) keys+{-# INLINE lookupLSized #-}++getBFstLL' :: (Eq k, Hashable k) => b -> [(k, b)] -> [k] -> [b]+getBFstLL' def pairs keys =+ (\(ST st_rep) -> case runRW# st_rep of (# _, a #) -> map (\x -> case x of { Just y -> y; ~rr -> def }) a)+ (lookupL pairs keys)+{-# INLINE getBFstLL' #-}++getBFstLArr' :: (Hashable k, Ix i, Eq k) => b -> [(k, b)] -> Array i k -> Array i b+getBFstLArr' def pairs keysArr =+ (\(ST st_rep) -> case runRW# st_rep of (# _, a #) -> amap (\x -> case x of { Just y -> y; ~rr -> def }) a)+ (lookupL pairs keysArr)+{-# INLINE getBFstLArr' #-}++getBFstLSized' :: (Eq k, Hashable k) => Int -> v -> [(k, v)] -> k -> v+getBFstLSized' n def pairs key = fromMaybe def .+ (\(ST st_rep) -> case runRW# st_rep of (# _, a #) -> a) . -- Actually is rewritten from the GHC.ST.runST to remove the forall constraint+ lookup2Sized n pairs $ key+{-# INLINE getBFstLSized' #-}++getBFstLLSized' :: (Eq k, Hashable k) => Int -> b -> [(k, b)] -> [k] -> [b]+getBFstLLSized' n def pairs keys =+ (\(ST st_rep) -> case runRW# st_rep of (# _, a #) -> map (\x -> case x of { Just y -> y; ~rr -> def }) a)+ (lookupLSized n pairs keys)+{-# INLINE getBFstLLSized' #-}++getBFstLArrSized' :: (Hashable k, Ix i, Eq k) => Int -> b -> [(k, b)] -> Array i k -> Array i b+getBFstLArrSized' n def pairs keysArr =+ (\(ST st_rep) -> case runRW# st_rep of (# _, a #) -> amap (\x -> case x of { Just y -> y; ~rr -> def }) a)+ (lookupLSized n pairs keysArr)+{-# INLINE getBFstLArrSized' #-}
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2020 OleksandrZhabenko++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ mmsyn2-hashable.cabal view
@@ -0,0 +1,26 @@+-- Initial mmsyn2-hashable.cabal file. For further+-- documentation, see http://haskell.org/cabal/users-guide/++name: mmsyn2-hashable+version: 0.1.0.0+synopsis: A library that can be used for multiple Hashable a => a -> b transformations.+description: A library that can be used as a @case ... of@ construction replacement for various cases. Forked from the mmsyn2-array-0.2.2.0.+homepage: https://hackage.haskell.org/package/mmsyn2-hashable+license: MIT+license-file: LICENSE+author: OleksandrZhabenko+maintainer: olexandr543@yahoo.com+copyright: Oleksandr Zhabenko+category: Development, Data, Language+build-type: Simple+extra-source-files: CHANGELOG.md+cabal-version: >=1.10++library+ exposed-modules: Case.Hashable.Cuckoo+ -- other-modules:+ other-extensions: UnboxedTuples, MagicHash+ ghc-options: -funbox-strict-fields+ build-depends: base >=4.9 && <5, hashtables >=1.2.3 && <2, hashable >= 1.2.7 && <2, ghc-prim >=0.5 && <1+ -- hs-source-dirs:+ default-language: Haskell2010