本文整理汇总了C#中UInt32.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# UInt32.Contains方法的具体用法?C# UInt32.Contains怎么用?C# UInt32.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UInt32
的用法示例。
在下文中一共展示了UInt32.Contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendBitField
public bool SendBitField(bool[] bitField, bool obsf)
{
UInt32[] obsfIDs = new UInt32[0];
if (obsf && bitField.Length > 32)
{
Random rand = new Random();
UInt32 obsfCount = (UInt32)Math.Min(16, bitField.Length / 16);
UInt32 distObsf = 0;
obsfIDs = new UInt32[obsfCount];
while (distObsf < obsfCount)
{
UInt32 piece = (UInt32)rand.Next(0, bitField.Length);
if (obsfIDs.Contains(piece)) continue;
obsfIDs[distObsf] = piece;
distObsf++;
}
}
byte[] bytes = new byte[bitField.Length / 8];
for (UInt32 i = 0; i < bitField.Length; i++)
{
if (obsfIDs.Contains(i)) continue;
int x = (int)Math.Floor((double)i/8);
ushort p = (ushort) (i%8);
if (bitField[i])
{
bytes[x] = bytes[x].SetBit(p);
}
}
int sent = Socket.Send(new PeerMessageBuilder(5).Add(bytes).Message());
if (obsfIDs.Length > 0)
{
foreach (UInt32 obsfID in obsfIDs)
{
SendHave(obsfID);
}
}
return sent == (5 + bitField.Length);
}