diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-06 00:01:49 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-06 00:01:49 +0400 |
commit | a467181b6aa21b1e41d56e7772d481cbf0c37f39 (patch) | |
tree | 2f0ad59b193b1f790d38d94110dc9b83a6864901 /src/Data | |
parent | 29036b62a5da2505862c904bc069c7b0b94129e4 (diff) |
Add check command to mktorrent utility
Diffstat (limited to 'src/Data')
-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 8cdae69f..b65f058b 100644 --- a/src/Data/Torrent/Bitfield.hs +++ b/src/Data/Torrent/Bitfield.hs | |||
@@ -57,6 +57,7 @@ module Data.Torrent.Bitfield | |||
57 | , isSubsetOf | 57 | , isSubsetOf |
58 | 58 | ||
59 | -- ** Availability | 59 | -- ** Availability |
60 | , complement | ||
60 | , Frequency | 61 | , Frequency |
61 | , frequencies | 62 | , frequencies |
62 | , rarest | 63 | , rarest |
@@ -194,8 +195,20 @@ findMax :: Bitfield -> PieceIx | |||
194 | findMax = S.findMax . bfSet | 195 | findMax = S.findMax . bfSet |
195 | {-# INLINE findMax #-} | 196 | {-# INLINE findMax #-} |
196 | 197 | ||
198 | -- | Check if all pieces from first bitfield present if the second bitfield | ||
197 | isSubsetOf :: Bitfield -> Bitfield -> Bool | 199 | isSubsetOf :: Bitfield -> Bitfield -> Bool |
198 | isSubsetOf a b = bfSet a `S.isSubsetOf` bfSet b | 200 | isSubsetOf a b = bfSet a `S.isSubsetOf` bfSet b |
201 | {-# INLINE isSubsetOf #-} | ||
202 | |||
203 | -- | Resulting bitfield includes only missing pieces. | ||
204 | complement :: Bitfield -> Bitfield | ||
205 | complement Bitfield {..} = Bitfield | ||
206 | { bfSet = uni `S.difference` bfSet | ||
207 | , bfSize = bfSize | ||
208 | } | ||
209 | where | ||
210 | Bitfield _ uni = haveAll bfSize | ||
211 | {-# INLINE complement #-} | ||
199 | 212 | ||
200 | {----------------------------------------------------------------------- | 213 | {----------------------------------------------------------------------- |
201 | -- Availability | 214 | -- Availability |