diff --git a/indexation.cabal b/indexation.cabal
--- a/indexation.cabal
+++ b/indexation.cabal
@@ -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
diff --git a/library/Indexation/Data.hs b/library/Indexation/Data.hs
--- a/library/Indexation/Data.hs
+++ b/library/Indexation/Data.hs
@@ -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
diff --git a/library/Indexation/FoldM/Basic.hs b/library/Indexation/FoldM/Basic.hs
new file mode 100644
--- /dev/null
+++ b/library/Indexation/FoldM/Basic.hs
@@ -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
diff --git a/library/Indexation/FoldM/Index.hs b/library/Indexation/FoldM/Index.hs
new file mode 100644
--- /dev/null
+++ b/library/Indexation/FoldM/Index.hs
@@ -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)
diff --git a/library/Indexation/Functions.hs b/library/Indexation/Functions.hs
--- a/library/Indexation/Functions.hs
+++ b/library/Indexation/Functions.hs
@@ -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)
diff --git a/library/Indexation/Instances.hs b/library/Indexation/Instances.hs
--- a/library/Indexation/Instances.hs
+++ b/library/Indexation/Instances.hs
@@ -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)
diff --git a/library/Indexation/Instances/Cereal.hs b/library/Indexation/Instances/Cereal.hs
--- a/library/Indexation/Instances/Cereal.hs
+++ b/library/Indexation/Instances/Cereal.hs
@@ -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)
diff --git a/library/Indexation/Prelude.hs b/library/Indexation/Prelude.hs
--- a/library/Indexation/Prelude.hs
+++ b/library/Indexation/Prelude.hs
@@ -107,6 +107,10 @@
 -------------------------
 import Data.Serialize as Exports (Serialize)
 
+-- cereal-vector
+-------------------------
+import Data.Vector.Serialize ()
+
 -- bytestring
 -------------------------
 import Data.ByteString as Exports (ByteString)
diff --git a/library/Indexation/Types.hs b/library/Indexation/Types.hs
--- a/library/Indexation/Types.hs
+++ b/library/Indexation/Types.hs
@@ -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)
