本文整理汇总了C#中BitSet.NextSetBit方法的典型用法代码示例。如果您正苦于以下问题:C# BitSet.NextSetBit方法的具体用法?C# BitSet.NextSetBit怎么用?C# BitSet.NextSetBit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitSet
的用法示例。
在下文中一共展示了BitSet.NextSetBit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Condense
protected virtual void Condense(float[] floats)
{
if (floats.Length != _capacity)
{
throw new ArgumentException("bad input float array of length " + floats.Length + " for capacity: " + _capacity);
}
var bits = new BitSet(floats.Length);
int on = 0;
for (int i = 0; i < floats.Length; i++)
{
if (floats[i] != 0f)
{
bits.Set(i);
on++;
}
}
if (((float)on) / ((float)floats.Length) < ON_RATIO_CUTOFF)
{
// it's worth compressing
if (0 == on)
{
// it's worth super-compressing
_floats = null;
_bits = null;
_referencePoints = null;
// capacity is good.
}
else
{
_bits = bits;
_floats = new float[_bits.Cardinality()];
_referencePoints = new int[floats.Length / REFERENCE_POINT_EVERY];
int i = 0;
int floatsIdx = 0;
int refIdx = 0;
while (i < floats.Length && (i = _bits.NextSetBit(i)) >= 0)
{
_floats[floatsIdx] = floats[i];
while (refIdx < i / REFERENCE_POINT_EVERY)
{
_referencePoints[refIdx++] = floatsIdx;
}
floatsIdx++;
i++;
}
while (refIdx < _referencePoints.Length)
{
_referencePoints[refIdx++] = floatsIdx;
}
}
}
else
{
// it's not worth compressing
_floats = floats;
_bits = null;
}
}