summaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-05 22:58:25 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-05 22:58:25 +0400
commit29036b62a5da2505862c904bc069c7b0b94129e4 (patch)
treee34734c822f525c2afbee720609ab5070146d2ac /src/Data
parent8d194406c7d23e610bf5227f52ee8e04a555e85d (diff)
Implement getBitfield and genPieceInfo functions
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Torrent/Bitfield.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Data/Torrent/Bitfield.hs b/src/Data/Torrent/Bitfield.hs
index 02a4c14f..8cdae69f 100644
--- a/src/Data/Torrent/Bitfield.hs
+++ b/src/Data/Torrent/Bitfield.hs
@@ -62,6 +62,7 @@ module Data.Torrent.Bitfield
62 , rarest 62 , rarest
63 63
64 -- * Combine 64 -- * Combine
65 , insert
65 , union 66 , union
66 , intersection 67 , intersection
67 , difference 68 , difference
@@ -196,6 +197,10 @@ findMax = S.findMax . bfSet
196isSubsetOf :: Bitfield -> Bitfield -> Bool 197isSubsetOf :: Bitfield -> Bitfield -> Bool
197isSubsetOf a b = bfSet a `S.isSubsetOf` bfSet b 198isSubsetOf a b = bfSet a `S.isSubsetOf` bfSet b
198 199
200{-----------------------------------------------------------------------
201-- Availability
202-----------------------------------------------------------------------}
203
199-- | Frequencies are needed in piece selection startegies which use 204-- | Frequencies are needed in piece selection startegies which use
200-- availability quantity to find out the optimal next piece index to 205-- availability quantity to find out the optimal next piece index to
201-- download. 206-- download.
@@ -240,6 +245,14 @@ rarest xs
240 Combine 245 Combine
241-----------------------------------------------------------------------} 246-----------------------------------------------------------------------}
242 247
248insert :: PieceIx -> Bitfield -> Bitfield
249insert pix bf @ Bitfield {..}
250 | 0 <= pix && pix < bfSize = Bitfield
251 { bfSet = S.insert pix bfSet
252 , bfSize = bfSize
253 }
254 | otherwise = bf
255
243-- | Find indices at least one peer have. 256-- | Find indices at least one peer have.
244union :: Bitfield -> Bitfield -> Bitfield 257union :: Bitfield -> Bitfield -> Bitfield
245union a b = {-# SCC union #-} Bitfield { 258union a b = {-# SCC union #-} Bitfield {