本文整理匯總了C#中BitField類的典型用法代碼示例。如果您正苦於以下問題:C# BitField類的具體用法?C# BitField怎麽用?C# BitField使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BitField類屬於命名空間,在下文中一共展示了BitField類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GenerateRarestFirst
private void GenerateRarestFirst(BitField peerBitfield, IEnumerable<PeerId> otherPeers)
{
// Move anything in the rarest buffer into the spares
while (_rarest.Count > 0)
_spares.Push(_rarest.Pop());
var current = DequeueSpare();
current.From(peerBitfield);
// Store this bitfield as the first iteration of the Rarest First algorithm.
_rarest.Push(current);
// Get a cloned copy of the bitfield and begin iterating to find the rarest pieces
foreach (var t in otherPeers.Where(t => !t.BitField.AllTrue))
{
current = DequeueSpare().From(current);
// currentBitfield = currentBitfield & (!otherBitfield)
// This calculation finds the pieces this peer has that other peers *do not* have.
// i.e. the rarest piece.
current.NAnd(t.BitField);
// If the bitfield now has no pieces we've completed our task
if (current.AllFalse)
{
_spares.Push(current);
break;
}
// Otherwise push the bitfield on the stack and clone it and iterate again.
_rarest.Push(current);
}
}
示例2: InitialSeedingMode
public InitialSeedingMode(TorrentManager manager)
: base(manager)
{
unchoker = new InitialSeedUnchoker(manager);
manager.chokeUnchoker = unchoker;
zero = new BitField(manager.Bitfield.Length);
}
示例3: PickPiece
public override MessageBundle PickPiece(PeerId id, BitField peerBitfield, List<PeerId> otherPeers, int count,
int startIndex, int endIndex)
{
// Only request 2 pieces at a time in endgame mode
// to prevent a *massive* overshoot
if (id.IsChoking || id.AmRequestingPiecesCount > 2)
return null;
LoadPieces(id, peerBitfield);
// 1) See if there are any blocks which have not been requested at all. Request the block if the peer has it
foreach (var p in pieces)
{
if (!peerBitfield[p.Index] || p.AllBlocksRequested)
continue;
for (var i = 0; i < p.BlockCount; i++)
{
if (p.Blocks[i].Requested)
continue;
p.Blocks[i].Requested = true;
var request = new Request(id, p.Blocks[i]);
requests.Add(request);
return new MessageBundle(request.Block.CreateRequest(id));
}
}
// 2) For each block with an existing request, add another request. We do a search from the start
// of the list to the end. So when we add a duplicate request, move both requests to the end of the list
foreach (var p in pieces)
{
if (!peerBitfield[p.Index])
continue;
for (var i = 0; i < p.BlockCount; i++)
{
if (p.Blocks[i].Received || AlreadyRequested(p.Blocks[i], id))
continue;
var c = requests.Count;
for (var j = 0; j < requests.Count - 1 && (c-- > 0); j++)
{
if (requests[j].Block.PieceIndex == p.Index &&
requests[j].Block.StartOffset == p.Blocks[i].StartOffset)
{
var r = requests[j];
requests.RemoveAt(j);
requests.Add(r);
j--;
}
}
p.Blocks[i].Requested = true;
var request = new Request(id, p.Blocks[i]);
requests.Add(request);
return new MessageBundle(request.Block.CreateRequest(id));
}
}
return null;
}
示例4: IsInteresting
public override bool IsInteresting(BitField bitfield)
{
temp.From(bitfield).NAnd(this.bitfield);
if (temp.AllFalse)
return false;
return base.IsInteresting(temp);
}
示例5: LinkedInGetMemberOptions
/// <summary>
/// Initializes new instance of LinkedInGetMemberOptions
/// </summary>
public LinkedInGetMemberOptions()
{
BasicProfileOptions = new BitField<LinkedInBasicProfileFields>();
EmailProfileOptions = new BitField<LinkedInEmailProfileFields>();
FullProfileOptions = new BitField<LinkedInFullProfileFields>();
Parameters = new LinkedInGetMemberParameters();
}
示例6: EndGamePickerTests
public EndGamePickerTests()
{
rig = TestRig.CreateMultiFile();
bitfield = new BitField(40).SetAll(true)
.Set(4, false)
.Set(6, false)
.Set(24, false)
.Set(36, false);
picker = new EndGamePicker();
pieces = new List<Piece>(new[]
{
new Piece(4, rig.Torrent.PieceLength, rig.Torrent.Size),
new Piece(6, rig.Torrent.PieceLength, rig.Torrent.Size),
new Piece(24, rig.Torrent.PieceLength, rig.Torrent.Size),
new Piece(36, rig.Torrent.PieceLength, rig.Torrent.Size)
});
id = new PeerId(new Peer("peerid", new Uri("tcp://weburl.com")), rig.Manager);
id.IsChoking = false;
id.BitField.SetAll(false);
other = new PeerId(new Peer("other", new Uri("tcp://other.com")), rig.Manager);
other.IsChoking = false;
other.BitField.SetAll(false);
}
示例7: Setup
public void Setup()
{
alreadyGot = new List<Block>();
bitfield = new BitField(40).SetAll(true);
picker = new EndGamePicker();
pieces = new List<Piece>(new Piece[] {
new Piece(4, rig.Torrent),
new Piece(6, rig.Torrent),
new Piece(36, rig.Torrent),
new Piece(24, rig.Torrent)
});
for (int i = 0; i < pieces.Count; i++)
{
for (int j = 0; j < pieces[i].BlockCount; j++)
{
if (j % 3 == 0)
{
pieces[i].Blocks[j].CreateRequest(id);
if (j % 2 == 0)
{
pieces[i].Blocks[j].Received = true;
}
pieces[i].Blocks[j].Requested = true;
alreadyGot.Add(pieces[i].Blocks[j]);
}
}
}
picker.Initialise(bitfield, rig.Torrent.Files, pieces);
}
示例8: InitialSeedUnchoker
public InitialSeedUnchoker(TorrentManager manager)
{
advertisedPieces = new List<SeededPiece>();
bitfield = new BitField(manager.Bitfield.Length);
this.manager = manager;
peers = new List<ChokeData>();
temp = new BitField(bitfield.Length);
}
示例9: SetUp
public void SetUp()
{
// The bool[] must be kept in sync with the byte[] constructor. They represent exactly the same thing.
initalValues = new bool[] { true, false, true, false, true, false, true, true, true, false, false, true };
secondValues = new bool[] { true, true, false, false, true, false, true, false, true, false, false, true };
initialByteValues = new byte[] { 171, 144 };
bf = new BitField(initalValues);
}
示例10: PickPiece
public override MessageBundle PickPiece(PeerId id, BitField peerBitfield, List<PeerId> otherPeers, int count,
int startIndex, int endIndex)
{
var bundle = ActivePicker.PickPiece(id, peerBitfield, otherPeers, count, startIndex, endIndex);
if (bundle == null && TryEnableEndgame())
return ActivePicker.PickPiece(id, peerBitfield, otherPeers, count, startIndex, endIndex);
return bundle;
}
示例11: Initialise
public override void Initialise(BitField bitfield, TorrentFile[] files, IEnumerable<Piece> requests)
{
this.bitfield = bitfield;
endgameSelector = new BitField(bitfield.Length);
this.files = files;
inEndgame = false;
TryEnableEndgame();
ActivePicker.Initialise(bitfield, files, requests);
}
示例12: PickPiece
public override MessageBundle PickPiece(PeerId id, BitField peerBitfield, List<PeerId> otherPeers, int count, int startIndex, int endIndex)
{
// Invert 'bitfield' and AND it with the peers bitfield
// Any pieces which are 'true' in the bitfield will not be downloaded
temp.From(peerBitfield).NAnd(bitfield);
if (temp.AllFalse)
return null;
return base.PickPiece(id, temp, otherPeers, count, startIndex, endIndex);
}
示例13: FastResume
public FastResume(InfoHash infoHash, BitField bitfield)
{
if (infoHash == null)
throw new ArgumentNullException(nameof(infoHash));
if (bitfield == null)
throw new ArgumentNullException(nameof(bitfield));
Infohash = infoHash;
Bitfield = bitfield;
}
示例14: FastResume
public FastResume(InfoHash infoHash, BitField bitfield)
{
if (infoHash == null)
throw new ArgumentNullException("infoHash");
if (bitfield == null)
throw new ArgumentNullException("bitfield");
this.infoHash = infoHash;
this.bitfield = bitfield;
}
示例15: FastResume
public FastResume(InfoHash infoHash, BitField bitfield, IEnumerable<Priority> priorities)
{
if (infoHash==null)
throw new ArgumentNullException("infoHash");
if(bitfield == null)
throw new ArgumentNullException("bitfield");
this.infoHash = infoHash;
this.bitfield = bitfield;
this.priorities = priorities.ToArray();
}