summaryrefslogtreecommitdiff
path: root/src/Data/Bitfield.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Bitfield.hs')
-rw-r--r--src/Data/Bitfield.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Data/Bitfield.hs b/src/Data/Bitfield.hs
index 7cd07123..1ceaf78b 100644
--- a/src/Data/Bitfield.hs
+++ b/src/Data/Bitfield.hs
@@ -56,6 +56,7 @@ import Data.Monoid
56import Data.Ratio 56import Data.Ratio
57 57
58 58
59-- | Pieces indexed from zero up to 'PieceCount' value.
59type PieceIx = Int 60type PieceIx = Int
60 61
61-- | Used to represent max set bound. Min set bound is always set to 62-- | Used to represent max set bound. Min set bound is always set to
@@ -162,7 +163,8 @@ frequencies xs = runST $ do
162 163
163-- TODO it seems like this operation is veeery slow 164-- TODO it seems like this operation is veeery slow
164 165
165-- | Find least available piece index. If no piece available return 'Nothing'. 166-- | Find least available piece index. If no piece available return
167-- 'Nothing'.
166rarest :: [Bitfield] -> Maybe PieceIx 168rarest :: [Bitfield] -> Maybe PieceIx
167rarest xs 169rarest xs
168 | V.null freqMap = Nothing 170 | V.null freqMap = Nothing
@@ -170,7 +172,9 @@ rarest xs
170 where 172 where
171 freqMap = frequencies xs 173 freqMap = frequencies xs
172 174
173 minIx :: PieceIx -> Frequency -> (PieceIx, Frequency) -> (PieceIx, Frequency) 175 minIx :: PieceIx -> Frequency
176 -> (PieceIx, Frequency)
177 -> (PieceIx, Frequency)
174 minIx ix fr acc@(_, fra) 178 minIx ix fr acc@(_, fra)
175 | fr < fra && fr > 0 = (ix, fr) 179 | fr < fra && fr > 0 = (ix, fr)
176 | otherwise = acc 180 | otherwise = acc
@@ -201,7 +205,7 @@ difference a b = Bitfield {
201 , bfSet = bfSet a `S.difference` bfSet b 205 , bfSet = bfSet a `S.difference` bfSet b
202 } 206 }
203 207
204-- | 208-- | Find indices the any of the peers have.
205unions :: [Bitfield] -> Bitfield 209unions :: [Bitfield] -> Bitfield
206unions = foldl' union (haveNone 0) 210unions = foldl' union (haveNone 0)
207 211