当前位置: 首页>>代码示例>>C#>>正文


C# BitSet.Cardinality方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:modulexcite,项目名称:BoboBrowse.Net,代码行数:45,代码来源:FilterTest.cs

示例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;
     }
 }
开发者ID:modulexcite,项目名称:BoboBrowse.Net,代码行数:58,代码来源:SparseFloatArray.cs


注:本文中的BitSet.Cardinality方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。