本文整理汇总了C#中BitSet.Cardinality方法的典型用法代码示例。如果您正苦于以下问题:C# BitSet.Cardinality方法的具体用法?C# BitSet.Cardinality怎么用?C# BitSet.Cardinality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitSet
的用法示例。
在下文中一共展示了BitSet.Cardinality方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestFilteredDocSetIterator
public void TestFilteredDocSetIterator()
{
var set1 = new IntArrayDocIdSet();
for (int i = 0; i < 100; i++)
{
set1.AddDoc(2 * i); // 100 even numbers
}
var filteredIter = new MyFilteredDocSetIterator(set1.Iterator());
var bs = new BitSet(200);
for (int i = 0; i < 100; ++i)
{
int n = 10 * i;
if (n < 200)
{
bs.Set(n);
}
}
try
{
int doc;
while ((doc = filteredIter.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
{
if (!bs.Get(doc))
{
Assert.Fail("failed: " + doc + " not in expected set");
return;
}
else
{
bs.Clear(doc);
}
}
if (bs.Cardinality() > 0)
{
Assert.Fail("failed: leftover cardinality: " + bs.Cardinality());
}
}
catch (Exception e)
{
Assert.Fail(e.Message);
}
}
示例2: 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;
}
}