cereal-unordered-containers (empty) → 0.1
raw patch · 8 files changed
+215/−0 lines, 8 filesdep +basedep +cerealdep +hashablesetup-changed
Dependencies added: base, cereal, hashable, unordered-containers
Files
- LICENSE +22/−0
- Setup.hs +2/−0
- cereal-unordered-containers.cabal +44/−0
- library/Cereal/UnorderedContainers/Extras/StrictHashMap.hs +29/−0
- library/Cereal/UnorderedContainers/Get.hs +11/−0
- library/Cereal/UnorderedContainers/Prelude.hs +80/−0
- library/Cereal/UnorderedContainers/Put.hs +12/−0
- library/Cereal/UnorderedContainers/Serialize.hs +15/−0
+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2018, Metrix.AI++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
+ cereal-unordered-containers.cabal view
@@ -0,0 +1,44 @@+name:+ cereal-unordered-containers+version:+ 0.1+synopsis:+ Integration of "cereal" and "unordered-containers"+homepage:+ https://github.com/metrix-ai/cereal-unordered-containers +bug-reports:+ https://github.com/metrix-ai/cereal-unordered-containers/issues +author:+ Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+ Metrix.AI Ninjas <ninjas@metrix.ai>+copyright:+ (c) 2018, Metrix.AI+license:+ MIT+license-file:+ LICENSE+build-type:+ Simple+cabal-version:+ >=1.10++library+ hs-source-dirs:+ library+ default-extensions:+ Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+ default-language:+ Haskell2010+ exposed-modules:+ Cereal.UnorderedContainers.Serialize+ Cereal.UnorderedContainers.Put+ Cereal.UnorderedContainers.Get+ other-modules:+ Cereal.UnorderedContainers.Prelude+ Cereal.UnorderedContainers.Extras.StrictHashMap+ build-depends:+ base <5,+ cereal >=0.5.5 && <0.6,+ hashable >=1.2 && <2,+ unordered-containers >=0.2 && <0.3
+ library/Cereal/UnorderedContainers/Extras/StrictHashMap.hs view
@@ -0,0 +1,29 @@+module Cereal.UnorderedContainers.Extras.StrictHashMap+(+ module Data.HashMap.Strict,+ traverse_,+ replicateM,+)+where++import Cereal.UnorderedContainers.Prelude hiding (traverse_, replicateM, insert, empty)+import Data.HashMap.Strict+++{-# INLINE traverse_ #-}+traverse_ :: Applicative m => (k -> v -> m ()) -> HashMap k v -> m ()+traverse_ m =+ foldrWithKey step init+ where+ init = pure ()+ step k v acc = m k v *> acc++{-# INLINE replicateM #-}+replicateM :: (Monad m, Eq k, Hashable k) => Int -> m (k, v) -> m (HashMap k v)+replicateM amount m = let+ iterate index !state = if index < amount+ then do+ (k, v) <- m+ iterate (succ index) (insert k v state)+ else return state+ in iterate 0 empty
+ library/Cereal/UnorderedContainers/Get.hs view
@@ -0,0 +1,11 @@+module Cereal.UnorderedContainers.Get+where++import Cereal.UnorderedContainers.Prelude+import qualified Cereal.UnorderedContainers.Extras.StrictHashMap as StrictHashMap+++strictHashMap :: (Eq key, Hashable key) => Get Int -> Get key -> Get value -> Get (StrictHashMap.HashMap key value)+strictHashMap int key value = size >>= associations where+ size = int+ associations size = StrictHashMap.replicateM size ((,) <$> key <*> value)
+ library/Cereal/UnorderedContainers/Prelude.hs view
@@ -0,0 +1,80 @@+module Cereal.UnorderedContainers.Prelude+(+ module Exports,+)+where+++-- base+-------------------------+import Control.Applicative as Exports+import Control.Arrow as Exports+import Control.Category as Exports+import Control.Concurrent as Exports+import Control.Exception as Exports+import Control.Monad as Exports hiding (mapM_, sequence_, forM_, msum, mapM, sequence, forM)+import Control.Monad.IO.Class as Exports+import Control.Monad.Fix as Exports hiding (fix)+import Control.Monad.ST as Exports+import Data.Bits as Exports+import Data.Bool as Exports+import Data.Char as Exports+import Data.Coerce as Exports+import Data.Complex as Exports+import Data.Data as Exports+import Data.Dynamic as Exports+import Data.Either as Exports+import Data.Fixed as Exports+import Data.Foldable as Exports+import Data.Function as Exports hiding (id, (.))+import Data.Functor as Exports+import Data.Functor.Identity as Exports+import Data.Int as Exports+import Data.IORef as Exports+import Data.Ix as Exports+import Data.List as Exports hiding (sortOn, isSubsequenceOf, uncons, concat, foldr, foldl1, maximum, minimum, product, sum, all, and, any, concatMap, elem, foldl, foldr1, notElem, or, find, maximumBy, minimumBy, mapAccumL, mapAccumR, foldl')+import Data.Maybe as Exports+import Data.Monoid as Exports hiding (Last(..), First(..), (<>))+import Data.Ord as Exports+import Data.Proxy as Exports+import Data.Ratio as Exports+import Data.Semigroup as Exports+import Data.STRef as Exports+import Data.String as Exports+import Data.Traversable as Exports+import Data.Tuple as Exports+import Data.Unique as Exports+import Data.Version as Exports+import Data.Word as Exports+import Debug.Trace as Exports+import Foreign.ForeignPtr as Exports+import Foreign.Ptr as Exports+import Foreign.StablePtr as Exports+import Foreign.Storable as Exports hiding (sizeOf, alignment)+import GHC.Conc as Exports hiding (withMVar, threadWaitWriteSTM, threadWaitWrite, threadWaitReadSTM, threadWaitRead)+import GHC.Exts as Exports (lazy, inline, sortWith, groupWith)+import GHC.Generics as Exports (Generic)+import GHC.IO.Exception as Exports+import Numeric as Exports+import Prelude as Exports hiding (concat, foldr, mapM_, sequence_, foldl1, maximum, minimum, product, sum, all, and, any, concatMap, elem, foldl, foldr1, notElem, or, mapM, sequence, id, (.))+import System.Environment as Exports+import System.Exit as Exports+import System.IO as Exports+import System.IO.Error as Exports+import System.IO.Unsafe as Exports+import System.Mem as Exports+import System.Mem.StableName as Exports+import System.Timeout as Exports+import Text.ParserCombinators.ReadP as Exports (ReadP, ReadS, readP_to_S, readS_to_P)+import Text.ParserCombinators.ReadPrec as Exports (ReadPrec, readPrec_to_P, readP_to_Prec, readPrec_to_S, readS_to_Prec)+import Text.Printf as Exports (printf, hPrintf)+import Text.Read as Exports (Read(..), readMaybe, readEither)+import Unsafe.Coerce as Exports++-- cereal+-------------------------+import Data.Serialize as Exports++-- hashable+-------------------------+import Data.Hashable as Exports (Hashable)
+ library/Cereal/UnorderedContainers/Put.hs view
@@ -0,0 +1,12 @@+module Cereal.UnorderedContainers.Put+where++import Cereal.UnorderedContainers.Prelude+import qualified Cereal.UnorderedContainers.Extras.StrictHashMap as StrictHashMap+++strictHashMap :: Putter Int -> Putter key -> Putter value -> Putter (StrictHashMap.HashMap key value)+strictHashMap int key value x = size *> associations where+ size = int (StrictHashMap.size x)+ associations = StrictHashMap.traverse_ association x+ association keyValue valueValue = key keyValue *> value valueValue
+ library/Cereal/UnorderedContainers/Serialize.hs view
@@ -0,0 +1,15 @@+{-|+Orphan instances of "Serialize".+-}+module Cereal.UnorderedContainers.Serialize+where++import Cereal.UnorderedContainers.Prelude+import qualified Cereal.UnorderedContainers.Put as Put+import qualified Cereal.UnorderedContainers.Get as Get+import qualified Cereal.UnorderedContainers.Extras.StrictHashMap as StrictHashMap+++instance (Eq key, Hashable key, Serialize key, Serialize value) => Serialize (StrictHashMap.HashMap key value) where+ put = Put.strictHashMap put put put+ get = Get.strictHashMap get get get