diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Data/Bitfield.hs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/Data/Bitfield.hs b/src/Data/Bitfield.hs index 024f8f71..3424a0c6 100644 --- a/src/Data/Bitfield.hs +++ b/src/Data/Bitfield.hs | |||
@@ -9,6 +9,7 @@ | |||
9 | -- bitfields. Bitfields are used to keep track indices of complete | 9 | -- bitfields. Bitfields are used to keep track indices of complete |
10 | -- pieces either peer have or client have. | 10 | -- pieces either peer have or client have. |
11 | -- | 11 | -- |
12 | {-# LANGUAGE CPP #-} | ||
12 | {-# LANGUAGE BangPatterns #-} | 13 | {-# LANGUAGE BangPatterns #-} |
13 | {-# LANGUAGE RecordWildCards #-} | 14 | {-# LANGUAGE RecordWildCards #-} |
14 | module Data.Bitfield | 15 | module Data.Bitfield |
@@ -32,8 +33,10 @@ module Data.Bitfield | |||
32 | , getBitfield, putBitfield | 33 | , getBitfield, putBitfield |
33 | , bitfieldByteCount | 34 | , bitfieldByteCount |
34 | 35 | ||
36 | -- #ifdef TESTING | ||
35 | , -- * Debug | 37 | , -- * Debug |
36 | mkBitfield | 38 | mkBitfield |
39 | -- #endif | ||
37 | ) where | 40 | ) where |
38 | 41 | ||
39 | import Control.Monad | 42 | import Control.Monad |
@@ -143,11 +146,13 @@ frequencies xs = runST $ do | |||
143 | where | 146 | where |
144 | size = maximum (map bfSize xs) | 147 | size = maximum (map bfSize xs) |
145 | 148 | ||
149 | -- TODO it seems like this operation is veeery slow | ||
150 | |||
146 | -- | Find least available piece index. If no piece available return 'Nothing'. | 151 | -- | Find least available piece index. If no piece available return 'Nothing'. |
147 | rarest :: [Bitfield] -> Maybe PieceIx | 152 | rarest :: [Bitfield] -> Maybe PieceIx |
148 | rarest xs | 153 | rarest xs |
149 | | V.null freqMap = Nothing | 154 | | V.null freqMap = Nothing |
150 | | otherwise = Just $ fst $ V.ifoldr minIx (0, freqMap V.! 0) freqMap | 155 | | otherwise = Just $ fst $ V.ifoldr' minIx (0, freqMap V.! 0) freqMap |
151 | where | 156 | where |
152 | freqMap = frequencies xs | 157 | freqMap = frequencies xs |
153 | 158 | ||
@@ -210,5 +215,5 @@ bitfieldByteCount = error "bitfieldByteCount" | |||
210 | mkBitfield :: PieceCount -> [PieceIx] -> Bitfield | 215 | mkBitfield :: PieceCount -> [PieceIx] -> Bitfield |
211 | mkBitfield s ixs = Bitfield { | 216 | mkBitfield s ixs = Bitfield { |
212 | bfSize = s | 217 | bfSize = s |
213 | , bfSet = S.splitLT s $ S.fromList ixs | 218 | , bfSet = S.splitGT (-1) $ S.splitLT s $ S.fromList ixs |
214 | } \ No newline at end of file | 219 | } \ No newline at end of file |