indexation 0.4.6 → 0.4.7
raw patch · 9 files changed
+64/−3 lines, 9 filesdep +cereal-vectordep +foldldep +vector-algorithmsPVP ok
version bump matches the API change (PVP)
Dependencies added: cereal-vector, foldl, vector-algorithms
API changes (from Hackage documentation)
+ Indexation.Data: data IndexCounts entity
+ Indexation.Data: indexSetByMinCount :: Word32 -> IndexCounts a -> IndexSet a
+ Indexation.Data: topCountedIndexSet :: Int -> IndexCounts a -> IndexSet a
+ Indexation.FoldM.Index: indexCounts :: Int -> FoldM IO (Index a) (IndexCounts a)
Files
- indexation.cabal +7/−2
- library/Indexation/Data.hs +1/−1
- library/Indexation/FoldM/Basic.hs +14/−0
- library/Indexation/FoldM/Index.hs +12/−0
- library/Indexation/Functions.hs +18/−0
- library/Indexation/Instances.hs +4/−0
- library/Indexation/Instances/Cereal.hs +2/−0
- library/Indexation/Prelude.hs +4/−0
- library/Indexation/Types.hs +2/−0
indexation.cabal view
@@ -1,5 +1,5 @@ name: indexation-version: 0.4.6+version: 0.4.7 category: Data synopsis: Tools for entity indexation description: A set of tools for indexing entities@@ -23,6 +23,7 @@ Indexation.Predicate Indexation.Potoki.Produce Indexation.Potoki.Transform+ Indexation.FoldM.Index other-modules: Indexation.Cereal.Get Indexation.Cereal.Put@@ -32,6 +33,7 @@ Indexation.Prelude Indexation.Types Indexation.Functions+ Indexation.FoldM.Basic Indexation.Utils.Vector Indexation.Utils.UnboxedVector Indexation.Utils.Unfoldr@@ -39,9 +41,11 @@ base >=4.11 && <5, bytestring >=0.10.8 && <0.11, cereal >=0.5.5 && <0.6,+ cereal-vector >=0.2.0.1 && <0.3, contravariant >=1.4 && <2, deferred-folds >=0.9 && <0.10, focus >=1.0.1 && <1.1,+ foldl >=1 && <2, hashable >=1 && <2, list-t >=1 && <1.1, mmorph >=1 && <2,@@ -52,4 +56,5 @@ text >=1 && <2, transformers >=0.5 && <0.6, unordered-containers >=0.2.9 && <0.3,- vector >=0.12 && <0.13+ vector >=0.12 && <0.13,+ vector-algorithms >=0.7.0.4 && <0.8
library/Indexation/Data.hs view
@@ -4,6 +4,6 @@ ) where -import Indexation.Types as Exports (Index(..), EntityTable, IndexTable, Indexer, IndexSet)+import Indexation.Types as Exports (Index(..), EntityTable, IndexTable, Indexer, IndexSet, IndexCounts) import Indexation.Instances () import Indexation.Functions as Exports
+ library/Indexation/FoldM/Basic.hs view
@@ -0,0 +1,14 @@+module Indexation.FoldM.Basic+where++import Indexation.Prelude+import Control.Foldl+import qualified Data.Vector.Unboxed as UnboxedVector+import qualified Data.Vector.Unboxed.Mutable as MutableUnboxedVector+++countIndices :: Int -> FoldM IO Int (UnboxedVector.Vector Word32)+countIndices amount = FoldM step init extract where+ init = MutableUnboxedVector.new amount+ step mv index = MutableUnboxedVector.modify mv succ index $> mv+ extract = UnboxedVector.unsafeFreeze
+ library/Indexation/FoldM/Index.hs view
@@ -0,0 +1,12 @@+module Indexation.FoldM.Index+where++import Indexation.Prelude+import Indexation.Types+import Indexation.Data+import Control.Foldl+import qualified Indexation.FoldM.Basic as Basic+++indexCounts :: Int -> FoldM IO (Index a) (IndexCounts a)+indexCounts amount = dimap (\ (Index x) -> x) IndexCounts (Basic.countIndices amount)
library/Indexation/Functions.hs view
@@ -7,6 +7,8 @@ import qualified Data.Vector as Vector import qualified Data.HashMap.Strict as HashMap import qualified Data.Vector.Unboxed as UnboxedVector+import qualified Data.Vector.Unboxed.Mutable as MutableUnboxedVector+import qualified Data.Vector.Algorithms.Intro as IntroVectorAlgorithm import qualified Indexation.Utils.UnboxedVector as UnboxedVector import qualified Indexation.Utils.Unfoldr as Unfoldr @@ -28,3 +30,19 @@ mergeIndexSets :: IndexSet entity -> IndexSet entity -> IndexSet entity mergeIndexSets (IndexSet vec1) (IndexSet vec2) = IndexSet $ UnboxedVector.zipWith (||) vec1 vec2++topCountedIndexSet :: Int -> IndexCounts a -> IndexSet a+topCountedIndexSet amount (IndexCounts countVec) = let+ countVecLength = UnboxedVector.length countVec+ limitedAmount = min amount countVecLength+ in runST $ do+ pairMVec <- UnboxedVector.unsafeThaw (UnboxedVector.imap (\ index count -> (count, index)) countVec)+ IntroVectorAlgorithm.selectBy (\ a b -> compare (fst b) (fst a)) pairMVec limitedAmount+ indexSetMVec <- MutableUnboxedVector.new countVecLength+ forM_ [0..(pred limitedAmount)] $ \ pairIndex -> do+ (_, index) <- MutableUnboxedVector.unsafeRead pairMVec pairIndex+ MutableUnboxedVector.write indexSetMVec index True+ IndexSet <$> UnboxedVector.unsafeFreeze indexSetMVec++indexSetByMinCount :: Word32 -> IndexCounts a -> IndexSet a+indexSetByMinCount min (IndexCounts countVec) = IndexSet (UnboxedVector.map (>= min) countVec)
library/Indexation/Instances.hs view
@@ -4,9 +4,13 @@ import Indexation.Prelude import Indexation.Types import Indexation.Instances.Cereal ()+import qualified Data.Vector.Unboxed as UnboxedVector instance Show (Index a) where show (Index int) = show int deriving instance Eq (Index a) deriving instance Ord (Index a) deriving instance Hashable (Index a)++instance Show (IndexSet a) where+ show = show . UnboxedVector.ifoldr (\ i -> bool id (i :)) [] . (\ (IndexSet x) -> x)
library/Indexation/Instances/Cereal.hs view
@@ -24,3 +24,5 @@ instance Serialize (IndexSet a) where get = IndexSet <$> Get.getVector get put (IndexSet vector) = Put.putVector put vector++deriving instance Serialize (IndexCounts a)
library/Indexation/Prelude.hs view
@@ -107,6 +107,10 @@ ------------------------- import Data.Serialize as Exports (Serialize) +-- cereal-vector+-------------------------+import Data.Vector.Serialize ()+ -- bytestring ------------------------- import Data.ByteString as Exports (ByteString)
library/Indexation/Types.hs view
@@ -19,3 +19,5 @@ A more efficient alternative to @HashSet (Index entity)@. -} newtype IndexSet entity = IndexSet (UnboxedVector.Vector Bool)++newtype IndexCounts entity = IndexCounts (UnboxedVector.Vector Word32)