本文整理汇总了C#中BitField类的典型用法代码示例。如果您正苦于以下问题:C# BitField类的具体用法?C# BitField怎么用?C# BitField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitField类属于命名空间,在下文中一共展示了BitField类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:haroldma,项目名称:Universal.Torrent,代码行数:33,代码来源:RarestFirstPicker.cs
示例2: InitialSeedingMode
public InitialSeedingMode(TorrentManager manager)
: base(manager)
{
unchoker = new InitialSeedUnchoker(manager);
manager.chokeUnchoker = unchoker;
zero = new BitField(manager.Bitfield.Length);
}
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:7,代码来源:InitialSeedingMode.cs
示例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;
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:60,代码来源:EndGamePicker.cs
示例4: IsInteresting
public override bool IsInteresting(BitField bitfield)
{
temp.From(bitfield).NAnd(this.bitfield);
if (temp.AllFalse)
return false;
return base.IsInteresting(temp);
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:7,代码来源:IgnoringPicker.cs
示例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();
}
开发者ID:keithshort,项目名称:HOPE,代码行数:10,代码来源:LinkedInGetMemberOptions.cs
示例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);
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:26,代码来源:EndGamePickerTests.cs
示例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);
}
开发者ID:burris,项目名称:monotorrent,代码行数:31,代码来源:EndGamePickerTests.cs
示例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);
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:8,代码来源:InitialSeedUnchoker.cs
示例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);
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:8,代码来源:BitFieldTest.cs
示例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;
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:8,代码来源:EndGameSwitcher.cs
示例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);
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:9,代码来源:EndGameSwitcher.cs
示例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);
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:9,代码来源:IgnoringPicker.cs
示例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;
}
开发者ID:haroldma,项目名称:Universal.Torrent,代码行数:10,代码来源:FastResume.cs
示例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;
}
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:10,代码来源:FastResume.cs
示例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();
}
开发者ID:silvermcd123,项目名称:WoWPrivateServerLauncher,代码行数:11,代码来源:FastResume.cs
示例16: Initialise
public override void Initialise(BitField bitfield, TorrentFile[] files, IEnumerable<Piece> requests)
{
// 'Requests' should contain a list of all the pieces we need to complete
pieces = new List<Piece>(requests);
foreach (var piece in pieces)
{
for (var i = 0; i < piece.BlockCount; i++)
if (piece.Blocks[i].RequestedOff != null)
this.requests.Add(new Request(piece.Blocks[i].RequestedOff, piece.Blocks[i]));
}
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:11,代码来源:EndGamePicker.cs
示例17: PickPiece
public override MessageBundle PickPiece(PeerId id, BitField peerBitfield, List<PeerId> otherPeers, int count, int startIndex, int endIndex)
{
if (peerBitfield.AllFalse)
return null;
if (count > 1)
return base.PickPiece(id, peerBitfield, otherPeers, count, startIndex, endIndex);
int midpoint = random.Next(startIndex, endIndex);
return base.PickPiece(id, peerBitfield, otherPeers, count, midpoint, endIndex) ??
base.PickPiece(id, peerBitfield, otherPeers, count, startIndex, midpoint);
}
开发者ID:Eskat0n,项目名称:OctoTorrent,代码行数:12,代码来源:RandomisedPicker.cs
示例18: LinkedInSearchOptions
/// <summary>
/// Initializes new instance of LinkedInSearchOptions
/// </summary>
public LinkedInSearchOptions()
{
Keywords = new List<string>();
MemberFieldOptions = new LinkedInGetMemberOptions();
FacetFields = new BitField<LinkedInFacetFields>();
BucketFields = new BitField<LinkedInBucketFields>();
FacetLanguageValues = new List<LinkedInFacetLanguage>();
FacetLocationValues = new List<string>();
FacetIndustryValues = new List<string>();
FacetCurrentCompanyValues = new List<string>();
FacetPastCompanyValues = new List<string>();
FacetSchoolValues = new List<string>();
}
开发者ID:keithshort,项目名称:HOPE,代码行数:16,代码来源:LinkedInSearchOptions.cs
示例19: InvalidBitfieldTest
public void InvalidBitfieldTest()
{
// Set each of the 4 trailing bits to 1 to force a decode error
for (byte i = 8; i > 0; i /= 2)
{
try
{
initialByteValues[1] += i;
bf = new BitField(initialByteValues, initalValues.Length);
Assert.Fail("The bitfield was corrupt but decoded correctly: Loop {0}", i);
}
catch (MessageException) { initialByteValues[1] -= i; }
}
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:14,代码来源:BitFieldTest.cs
示例20: And
public void And()
{
var bf2 = new BitField(_secondValues);
_bf.And(bf2);
Assert.AreEqual(new BitField(_secondValues), bf2, "#1: bf2 should be unmodified");
for (var i = 0; i < _bf.Length; i++)
Assert.AreEqual(_initalValues[i] && _secondValues[i], _bf[i], "#2");
var count = _initalValues
.Where((x, i) => x && _secondValues[i])
.Count();
Assert.AreEqual(count, _bf.TrueCount, "#3");
}
开发者ID:mrscylla,项目名称:octotorrent,代码行数:15,代码来源:BitFieldTest.cs
注:本文中的BitField类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论