From a467181b6aa21b1e41d56e7772d481cbf0c37f39 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Mon, 6 Jan 2014 00:01:49 +0400 Subject: Add check command to mktorrent utility --- src/Data/Torrent/Bitfield.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Data/Torrent/Bitfield.hs') 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 , isSubsetOf -- ** Availability + , complement , Frequency , frequencies , rarest @@ -194,8 +195,20 @@ findMax :: Bitfield -> PieceIx findMax = S.findMax . bfSet {-# INLINE findMax #-} +-- | Check if all pieces from first bitfield present if the second bitfield isSubsetOf :: Bitfield -> Bitfield -> Bool isSubsetOf a b = bfSet a `S.isSubsetOf` bfSet b +{-# INLINE isSubsetOf #-} + +-- | Resulting bitfield includes only missing pieces. +complement :: Bitfield -> Bitfield +complement Bitfield {..} = Bitfield + { bfSet = uni `S.difference` bfSet + , bfSize = bfSize + } + where + Bitfield _ uni = haveAll bfSize +{-# INLINE complement #-} {----------------------------------------------------------------------- -- Availability -- cgit v1.2.3