Package DebTorrent :: Module bitfield :: Class Bitfield
[hide private]
[frames] | no frames]

Class Bitfield

source code

A bitfield, a indicating the pieces a peer has.

Instance Methods [hide private]
 
__init__(self, length=None, bitstring=None, copyfrom=None) source code
 
__setitem__(self, index, val)
Set one of the bitfield entries.
source code
boolean
__getitem__(self, index)
Get one of the bitfield entries.
source code
int
__len__(self)
Get the length of the bitfield.
source code
string
tostring(self)
Convert the bitfield to a string
source code
boolean
complete(self)
Check if the bitfield is all true.
source code
Instance Variables [hide private]
list of boolean array
the bitfield
int length
the length of the bitfield
int numfalse
the number of false entries in the bitfield
Method Details [hide private]

__init__(self, length=None, bitstring=None, copyfrom=None)
(Constructor)

source code 
Parameters:
  • length (int) - the length of the bitfield to create (optional, if missing use length of copyfrom)
  • bitstring (string) - the bitfield string to initialize the bitfield from (optional, default is to initialize all to false)
  • copyfrom (Bitfield) - another bitfield to make a copy of (optional, default is to create a new empty one)

__setitem__(self, index, val)
(Index assignment operator)

source code 
Set one of the bitfield entries.
Parameters:
  • index (int) - the index to set
  • val (boolean) - the value to set to

__getitem__(self, index)
(Indexing operator)

source code 
Get one of the bitfield entries.
Parameters:
  • index (int) - the index to get
Returns: boolean
the value of the bitfield entry

__len__(self)
(Length operator)

source code 
Get the length of the bitfield.
Returns: int
the length of the bitfield

tostring(self)

source code 
Convert the bitfield to a string
Returns: string
the bitfield represented as a string

complete(self)

source code 
Check if the bitfield is all true.
Returns: boolean
whether the bitfield is complete (all true)