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.hs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/Data/Bitfield.hs b/src/Data/Bitfield.hs
index 89461fd2..acfca0d0 100644
--- a/src/Data/Bitfield.hs
+++ b/src/Data/Bitfield.hs
@@ -236,28 +236,28 @@ rarest xs
236 236
237-- | Find indices at least one peer have. 237-- | Find indices at least one peer have.
238union :: Bitfield -> Bitfield -> Bitfield 238union :: Bitfield -> Bitfield -> Bitfield
239union a b = Bitfield { 239union a b = {-# SCC union #-} Bitfield {
240 bfSize = bfSize a `max` bfSize b 240 bfSize = bfSize a `max` bfSize b
241 , bfSet = bfSet a `S.union` bfSet b 241 , bfSet = bfSet a `S.union` bfSet b
242 } 242 }
243 243
244-- | Find indices both peers have. 244-- | Find indices both peers have.
245intersection :: Bitfield -> Bitfield -> Bitfield 245intersection :: Bitfield -> Bitfield -> Bitfield
246intersection a b = Bitfield { 246intersection a b = {-# SCC intersection #-} Bitfield {
247 bfSize = bfSize a `min` bfSize b 247 bfSize = bfSize a `min` bfSize b
248 , bfSet = bfSet a `S.intersection` bfSet b 248 , bfSet = bfSet a `S.intersection` bfSet b
249 } 249 }
250 250
251-- | Find indices which have first peer but do not have the second peer. 251-- | Find indices which have first peer but do not have the second peer.
252difference :: Bitfield -> Bitfield -> Bitfield 252difference :: Bitfield -> Bitfield -> Bitfield
253difference a b = Bitfield { 253difference a b = {-# SCC difference #-} Bitfield {
254 bfSize = bfSize a -- FIXME is it reasonable? 254 bfSize = bfSize a -- FIXME is it reasonable?
255 , bfSet = bfSet a `S.difference` bfSet b 255 , bfSet = bfSet a `S.difference` bfSet b
256 } 256 }
257 257
258-- | Find indices the any of the peers have. 258-- | Find indices the any of the peers have.
259unions :: [Bitfield] -> Bitfield 259unions :: [Bitfield] -> Bitfield
260unions = foldl' union (haveNone 0) 260unions = {-# SCC unions #-} foldl' union (haveNone 0)
261 261
262{----------------------------------------------------------------------- 262{-----------------------------------------------------------------------
263 Serialization 263 Serialization
@@ -270,7 +270,7 @@ toList Bitfield {..} = S.toList bfSet
270-- | Unpack 'Bitfield' from tightly packed bit array. Note resulting 270-- | Unpack 'Bitfield' from tightly packed bit array. Note resulting
271-- size might be more than real bitfield size, use 'adjustSize'. 271-- size might be more than real bitfield size, use 'adjustSize'.
272fromBitmap :: ByteString -> Bitfield 272fromBitmap :: ByteString -> Bitfield
273fromBitmap bs = Bitfield { 273fromBitmap bs = {-# SCC fromBitmap #-} Bitfield {
274 bfSize = B.length bs * 8 274 bfSize = B.length bs * 8
275 , bfSet = S.fromByteString bs 275 , bfSet = S.fromByteString bs
276 } 276 }
@@ -278,7 +278,7 @@ fromBitmap bs = Bitfield {
278 278
279-- | Pack a 'Bitfield' to tightly packed bit array. 279-- | Pack a 'Bitfield' to tightly packed bit array.
280toBitmap :: Bitfield -> Lazy.ByteString 280toBitmap :: Bitfield -> Lazy.ByteString
281toBitmap Bitfield {..} = Lazy.fromChunks [intsetBM, alignment] 281toBitmap Bitfield {..} = {-# SCC toBitmap #-} Lazy.fromChunks [intsetBM, alignment]
282 where 282 where
283 byteSize = bfSize `div` 8 + if bfSize `mod` 8 == 0 then 0 else 1 283 byteSize = bfSize `div` 8 + if bfSize `mod` 8 == 0 then 0 else 1
284 alignment = B.replicate (byteSize - B.length intsetBM) 0 284 alignment = B.replicate (byteSize - B.length intsetBM) 0