indexation 0.2.1 → 0.3
raw patch · 12 files changed
+73/−145 lines, 12 filesdep −foldlPVP ok
version bump matches the API change (PVP)
Dependencies removed: foldl
API changes (from Hackage documentation)
- Indexation.EntityTable: data EntityTable entity
- Indexation.EntityTable: indexTable :: IndexTable entity -> EntityTable entity
- Indexation.EntityTable: lookup :: Index entity -> EntityTable entity -> Maybe entity
- Indexation.IO: indexProduceToFiles :: (Eq entity, Hashable entity, Serialize entity) => FilePath -> FilePath -> Produce entity -> IO (Either IOException ())
- Indexation.IO: readIndexTableFromFile :: (Serialize entity, Eq entity, Hashable entity) => FilePath -> IO (Either IOException (Either Text (IndexTable entity)))
- Indexation.Index: Index :: Int -> Index entity
- Indexation.Index: newtype Index entity
- Indexation.IndexTable: data IndexTable entity
- Indexation.IndexTable: empty :: (Eq entity, Hashable entity) => IndexTable entity
- Indexation.IndexTable: lookup :: (Eq entity, Hashable entity) => entity -> IndexTable entity -> Maybe (Index entity)
- Indexation.IndexTable: register :: (Eq entity, Hashable entity) => entity -> IndexTable entity -> (Index entity, IndexTable entity)
- Indexation.Potoki.Produce: indicesFromFile :: FilePath -> Produce (Either IOException (Either Text (Index a)))
- Indexation.Potoki.Transform: indexConcurrently :: (Eq entity, Hashable entity) => Indexer entity -> Transform entity (Index entity)
+ Indexation.Data: Index :: Int -> Index entity
+ Indexation.Data: data EntityTable entity
+ Indexation.Data: data Indexer entity
+ Indexation.Data: newtype Index entity
+ Indexation.IO: data EntityTable entity
+ Indexation.IO: data Indexer entity
+ Indexation.IO: freezeIndexerAsEntityTable :: Indexer entity -> IO (EntityTable entity)
+ Indexation.IO: getIndexerSize :: Indexer entity -> IO Int
+ Indexation.IO: serializeEntityTableToFile :: Serialize entity => EntityTable entity -> FilePath -> IO (Either IOException ())
+ Indexation.Potoki.Transform: Index :: Int -> Index entity
+ Indexation.Potoki.Transform: data EntityTable entity
+ Indexation.Potoki.Transform: data Indexer entity
+ Indexation.Potoki.Transform: data Transform input output
+ Indexation.Potoki.Transform: index :: (Eq entity, Hashable entity) => Indexer entity -> Transform entity (Index entity)
+ Indexation.Potoki.Transform: lookup :: EntityTable entity -> Transform (Index entity) (Maybe entity)
+ Indexation.Potoki.Transform: newtype Index entity
- Indexation.IO: serializeIndexerToFile :: Serialize entity => FilePath -> Indexer entity -> IO (Either IOException ())
+ Indexation.IO: serializeIndexerToFile :: Serialize a => (Text -> IO ()) -> FilePath -> Indexer a -> IO (Either IOException ())
Files
- indexation.cabal +5/−9
- library/Indexation/Data.hs +10/−0
- library/Indexation/EntityTable.hs +0/−18
- library/Indexation/Folds.hs +0/−22
- library/Indexation/IO.hs +24/−33
- library/Indexation/Index.hs +0/−9
- library/Indexation/IndexTable.hs +0/−33
- library/Indexation/Instances.hs +12/−0
- library/Indexation/Potoki/Produce.hs +0/−12
- library/Indexation/Potoki/Transform.hs +21/−4
- library/Indexation/Prelude.hs +0/−4
- library/Indexation/Types.hs +1/−1
indexation.cabal view
@@ -1,7 +1,7 @@ name: indexation version:- 0.2.1+ 0.3 category: Data synopsis:@@ -41,17 +41,14 @@ default-language: Haskell2010 exposed-modules:- Indexation.EntityTable- Indexation.Index- Indexation.IndexTable+ Indexation.Data Indexation.IO- Indexation.Potoki.Produce Indexation.Potoki.Transform other-modules: Indexation.Cereal.Get Indexation.Cereal.Put Indexation.Constructors.EntityTable- Indexation.Folds+ Indexation.Instances Indexation.Instances.Cereal Indexation.Prelude Indexation.Types@@ -62,13 +59,12 @@ cereal >=0.5.5 && <0.6, deferred-folds >=0.6 && <0.7, focus >=1.0.1 && <1.1,- foldl >=1 && <2, hashable >=1 && <2,- potoki-cereal >=0.3 && <0.4, potoki >=2 && <2.1,+ potoki-cereal >=0.3 && <0.4, profunctors >=5.2 && <6, stm-containers >=1 && <1.1,- transformers >=0.5 && <0.6, text >=1 && <2,+ transformers >=0.5 && <0.6, unordered-containers >=0.2.9 && <0.3, vector >=0.12 && <0.13
+ library/Indexation/Data.hs view
@@ -0,0 +1,10 @@+module Indexation.Data+(+ Index(..),+ EntityTable,+ Indexer,+)+where++import Indexation.Types+import Indexation.Instances ()
− library/Indexation/EntityTable.hs
@@ -1,18 +0,0 @@-module Indexation.EntityTable-(- EntityTable,- indexTable,- lookup,-)-where--import Indexation.Prelude hiding (lookup)-import Indexation.Types-import Indexation.Instances.Cereal ()-import Indexation.Constructors.EntityTable-import qualified Data.Vector as B---lookup :: Index entity -> EntityTable entity -> Maybe entity-lookup (Index indexPrim) (EntityTable vector) =- vector B.!? indexPrim
− library/Indexation/Folds.hs
@@ -1,22 +0,0 @@-module Indexation.Folds-where--import Indexation.Prelude-import Indexation.Types-import Control.Foldl-import qualified Data.HashMap.Strict as B---indexTable :: (Eq entity, Hashable entity) => Fold entity (IndexTable entity)-indexTable =- Fold step init extract- where- init = IndexTable 0 B.empty- step (IndexTable index map) key =- case B.lookup key map of- Just _ -> IndexTable index map- Nothing -> let- newMap = B.insert key index map- newIndex = succ index- in IndexTable newIndex newMap- extract = id
library/Indexation/IO.hs view
@@ -1,17 +1,20 @@ module Indexation.IO (+ Indexer,+ EntityTable, createIndexer,+ getIndexerSize,+ freezeIndexerAsEntityTable,+ serializeEntityTableToFile, serializeIndexerToFile,- indexProduceToFiles, readEntitiesAmountFromEntityTableFile, readEntityTableFromFile,- readIndexTableFromFile, ) where import Indexation.Prelude import Indexation.Types-import Indexation.Instances.Cereal ()+import Indexation.Instances () import qualified Potoki.IO as PotokiIo import qualified Potoki.Produce as PotokiProduce import qualified Potoki.Consume as PotokiConsume@@ -30,36 +33,30 @@ map <- StmMap.newIO return (Indexer sizeVar map) -createIndexerVector :: Indexer entity -> IO (Vector entity)-createIndexerVector (Indexer sizeVar map) =+getIndexerSize :: Indexer entity -> IO Int+getIndexerSize (Indexer sizeVar _) = atomically (readTVar sizeVar)++freezeIndexerAsVector :: Indexer entity -> IO (Vector entity)+freezeIndexerAsVector (Indexer sizeVar map) = atomically $ do size <- readTVar sizeVar Vector.unfoldM size (fmap swap (StmMap.unfoldM map)) -createIndexerEntityTable :: Indexer entity -> IO (EntityTable entity)-createIndexerEntityTable = fmap EntityTable . createIndexerVector--serializeProduceEntityIndicesToFile :: (Eq entity, Hashable entity) => FilePath -> Indexer entity -> Produce entity -> IO (Either IOException ())-serializeProduceEntityIndicesToFile path indexer entityProduce =- PotokiIo.produceAndConsume entityProduce $- PotokiConsume.transform (PotokiTransform.indexConcurrently indexer) $- PotokiConsume.encodeToFile path+freezeIndexerAsEntityTable :: Indexer entity -> IO (EntityTable entity)+freezeIndexerAsEntityTable = fmap EntityTable . freezeIndexerAsVector -serializeIndexerToFile :: Serialize entity => FilePath -> Indexer entity -> IO (Either IOException ())-serializeIndexerToFile path indexer = do- entityTable <- createIndexerEntityTable indexer- let- produce = PotokiProduce.put (Cereal.put entityTable)- consume = PotokiConsume.writeBytesToFile path- in PotokiIo.produceAndConsume produce consume+serializeEntityTableToFile :: Serialize entity => EntityTable entity -> FilePath -> IO (Either IOException ())+serializeEntityTableToFile entityTable path = let+ produce = PotokiProduce.put (Cereal.put entityTable)+ consume = PotokiConsume.writeBytesToFile path+ in PotokiIo.produceAndConsume produce consume -indexProduceToFiles :: (Eq entity, Hashable entity, Serialize entity) => FilePath {-^ Entity table -} -> FilePath {-^ Index stream -} -> Produce entity -> IO (Either IOException ())-indexProduceToFiles entityTablePath indexStreamPath entityProduce =- do- indexer <- createIndexer- runExceptT $ do- ExceptT (serializeProduceEntityIndicesToFile indexStreamPath indexer entityProduce)- ExceptT (serializeIndexerToFile entityTablePath indexer)+serializeIndexerToFile :: Serialize a => (Text -> IO ()) -> FilePath -> Indexer a -> IO (Either IOException ())+serializeIndexerToFile log file indexer = do+ log "Freezing"+ entityTable <- freezeIndexerAsEntityTable indexer+ log "Writing to file"+ serializeEntityTableToFile entityTable file readEntitiesAmountFromEntityTableFile :: FilePath -> IO (Either IOException Int) readEntitiesAmountFromEntityTableFile filePath =@@ -71,12 +68,6 @@ readEntityTableFromFile :: Serialize entity => FilePath -> IO (Either IOException (Either Text (EntityTable entity))) readEntityTableFromFile filePath =- PotokiIo.produceAndConsume- (PotokiProduce.fileBytes filePath)- (right' (PotokiConsume.get Cereal.get))--readIndexTableFromFile :: (Serialize entity, Eq entity, Hashable entity) => FilePath -> IO (Either IOException (Either Text (IndexTable entity)))-readIndexTableFromFile filePath = PotokiIo.produceAndConsume (PotokiProduce.fileBytes filePath) (right' (PotokiConsume.get Cereal.get))
− library/Indexation/Index.hs
@@ -1,9 +0,0 @@-module Indexation.Index-(- Index(..),-)-where--import Indexation.Prelude-import Indexation.Types-import Indexation.Instances.Cereal ()
− library/Indexation/IndexTable.hs
@@ -1,33 +0,0 @@-module Indexation.IndexTable-(- IndexTable,- lookup,- register,- empty,-)-where--import Indexation.Prelude hiding (lookup, empty)-import Indexation.Types-import Indexation.Instances.Cereal ()-import qualified Data.HashMap.Strict as A---lookup :: (Eq entity, Hashable entity) => entity -> IndexTable entity -> Maybe (Index entity)-lookup entity (IndexTable size hashMap) =- fmap Index (A.lookup entity hashMap)--register :: (Eq entity, Hashable entity) => entity -> IndexTable entity -> (Index entity, IndexTable entity)-register entity (IndexTable size hashMap) =- A.lookup entity hashMap & \ case- Just index -> (Index index, IndexTable size hashMap)- Nothing -> let- newSize = succ size- newHashMap = A.insert entity size hashMap- index = Index size- newTable = IndexTable newSize newHashMap- in (index, newTable)--empty :: (Eq entity, Hashable entity) => IndexTable entity-empty =- IndexTable 0 mempty
+ library/Indexation/Instances.hs view
@@ -0,0 +1,12 @@+module Indexation.Instances+where++import Indexation.Prelude+import Indexation.Types+import Indexation.Instances.Cereal ()+++deriving instance Show (Index a)+deriving instance Eq (Index a)+deriving instance Ord (Index a)+deriving instance Hashable (Index a)
− library/Indexation/Potoki/Produce.hs
@@ -1,12 +0,0 @@-module Indexation.Potoki.Produce where--import Indexation.Prelude-import Indexation.Types-import Indexation.Instances.Cereal ()-import Potoki.Produce-import Potoki.Cereal.Produce---indicesFromFile :: FilePath -> Produce (Either IOException (Either Text (Index a)))-indicesFromFile path =- fileDecoded path
library/Indexation/Potoki/Transform.hs view
@@ -1,14 +1,25 @@-module Indexation.Potoki.Transform where+module Indexation.Potoki.Transform+(+ Transform,+ Index(..),+ Indexer,+ EntityTable,+ index,+ lookup,+)+where -import Indexation.Prelude hiding (runState)+import Indexation.Prelude hiding (runState, index, lookup) import Indexation.Types+import Indexation.Instances () import Potoki.Transform import qualified Focus import qualified StmContainers.Map as StmMap+import qualified Data.Vector as Vector -indexConcurrently :: (Eq entity, Hashable entity) => Indexer entity -> Transform entity (Index entity)-indexConcurrently (Indexer sizeVar map) =+index :: (Eq entity, Hashable entity) => Indexer entity -> Transform entity (Index entity)+index (Indexer sizeVar map) = mapInIO $ \ entity -> atomically $ StmMap.focus focus entity map where focus = Focus.Focus conceal reveal where@@ -17,3 +28,9 @@ writeTVar sizeVar $! succ size return (Index size, Focus.Set size) reveal indexInt = return (Index indexInt, Focus.Leave)++lookup :: EntityTable entity -> Transform (Index entity) (Maybe entity)+lookup (EntityTable entityTableVector) =+ arr $ \ (Index indexInt) -> if Vector.length entityTableVector > indexInt+ then Just $! Vector.unsafeIndex entityTableVector indexInt+ else Nothing
library/Indexation/Prelude.hs view
@@ -85,10 +85,6 @@ import DeferredFolds.Unfold as Exports (Unfold(..)) import DeferredFolds.UnfoldM as Exports (UnfoldM(..)) --- foldl---------------------------import Control.Foldl as Exports (Fold(..), FoldM(..))- -- hashable ------------------------- import Data.Hashable as Exports (Hashable(..))
library/Indexation/Types.hs view
@@ -5,7 +5,7 @@ import qualified StmContainers.Map as A -data Indexer entity = Indexer (TVar Int) (A.Map entity Int)+data Indexer entity = Indexer {-# UNPACK #-} !(TVar Int) {-# UNPACK #-} !(A.Map entity Int) data IndexTable entity = IndexTable {-# UNPACK #-} !Int {-# UNPACK #-} !(HashMap entity Int)