本文整理匯總了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;
}
}