diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-05 22:58:25 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-05 22:58:25 +0400 |
commit | 29036b62a5da2505862c904bc069c7b0b94129e4 (patch) | |
tree | e34734c822f525c2afbee720609ab5070146d2ac /src/Data/Torrent | |
parent | 8d194406c7d23e610bf5227f52ee8e04a555e85d (diff) |
Implement getBitfield and genPieceInfo functions
Diffstat (limited to 'src/Data/Torrent')
-rw-r--r-- | src/Data/Torrent/Bitfield.hs | 13 |
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 | |||
196 | isSubsetOf :: Bitfield -> Bitfield -> Bool | 197 | isSubsetOf :: Bitfield -> Bitfield -> Bool |
197 | isSubsetOf a b = bfSet a `S.isSubsetOf` bfSet b | 198 | isSubsetOf 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 | ||
248 | insert :: PieceIx -> Bitfield -> Bitfield | ||
249 | insert 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. |
244 | union :: Bitfield -> Bitfield -> Bitfield | 257 | union :: Bitfield -> Bitfield -> Bitfield |
245 | union a b = {-# SCC union #-} Bitfield { | 258 | union a b = {-# SCC union #-} Bitfield { |