From 29036b62a5da2505862c904bc069c7b0b94129e4 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sun, 5 Jan 2014 22:58:25 +0400 Subject: Implement getBitfield and genPieceInfo functions --- src/Data/Torrent/Bitfield.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Data') 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 , rarest -- * Combine + , insert , union , intersection , difference @@ -196,6 +197,10 @@ findMax = S.findMax . bfSet isSubsetOf :: Bitfield -> Bitfield -> Bool isSubsetOf a b = bfSet a `S.isSubsetOf` bfSet b +{----------------------------------------------------------------------- +-- Availability +-----------------------------------------------------------------------} + -- | Frequencies are needed in piece selection startegies which use -- availability quantity to find out the optimal next piece index to -- download. @@ -240,6 +245,14 @@ rarest xs Combine -----------------------------------------------------------------------} +insert :: PieceIx -> Bitfield -> Bitfield +insert pix bf @ Bitfield {..} + | 0 <= pix && pix < bfSize = Bitfield + { bfSet = S.insert pix bfSet + , bfSize = bfSize + } + | otherwise = bf + -- | Find indices at least one peer have. union :: Bitfield -> Bitfield -> Bitfield union a b = {-# SCC union #-} Bitfield { -- cgit v1.2.3