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


C# BitArray.Cardinality方法代码示例

本文整理汇总了C#中System.Collections.BitArray.Cardinality方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.Cardinality方法的具体用法?C# BitArray.Cardinality怎么用?C# BitArray.Cardinality使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.BitArray的用法示例。


在下文中一共展示了BitArray.Cardinality方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCompact

 public virtual void TestCompact()
 {
     BytesRef @ref = new BytesRef();
     int num = AtLeast(2);
     for (int j = 0; j < num; j++)
     {
         int numEntries = 0;
         const int size = 797;
         BitArray bits = new BitArray(size);
         for (int i = 0; i < size; i++)
         {
             string str;
             do
             {
                 str = TestUtil.RandomRealisticUnicodeString(Random(), 1000);
             } while (str.Length == 0);
             @ref.CopyChars(str);
             int key = Hash.Add(@ref);
             if (key < 0)
             {
                 Assert.IsTrue(bits.SafeGet((-key) - 1));
             }
             else
             {
                 Assert.IsFalse(bits.SafeGet(key));
                 bits.SafeSet(key, true);
                 numEntries++;
             }
         }
         Assert.AreEqual(Hash.Size(), bits.Cardinality());
         Assert.AreEqual(numEntries, bits.Cardinality());
         Assert.AreEqual(numEntries, Hash.Size());
         int[] compact = Hash.Compact();
         Assert.IsTrue(numEntries < compact.Length);
         for (int i = 0; i < numEntries; i++)
         {
             bits.SafeSet(compact[i], false);
         }
         Assert.AreEqual(0, bits.Cardinality());
         Hash.Clear();
         Assert.AreEqual(0, Hash.Size());
         Hash.Reinit();
     }
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:44,代码来源:TestBytesRefHash.cs

示例2: DoRandomSets

        internal virtual void DoRandomSets(int maxSize, int iter, int mode)
        {
            BitArray a0 = null;
            LongBitSet b0 = null;

            for (int i = 0; i < iter; i++)
            {
                int sz = TestUtil.NextInt(Random(), 2, maxSize);
                BitArray a = new BitArray(sz);
                LongBitSet b = new LongBitSet(sz);

                // test the various ways of setting bits
                if (sz > 0)
                {
                    int nOper = Random().Next(sz);
                    for (int j = 0; j < nOper; j++)
                    {
                        int idx;

                        idx = Random().Next(sz);
                        a.SafeSet(idx, true);
                        b.Set(idx);

                        idx = Random().Next(sz);
                        a.SafeSet(idx, false);
                        b.Clear(idx);

                        idx = Random().Next(sz);
                        a.SafeSet(idx, !a.SafeGet(idx));
                        b.Flip(idx, idx + 1);

                        idx = Random().Next(sz);
                        a.SafeSet(idx, !a.SafeGet(idx));
                        b.Flip(idx, idx + 1);
                        
                        bool val2 = b.Get(idx);
                        bool val = b.GetAndSet(idx);
                        Assert.IsTrue(val2 == val);
                        Assert.IsTrue(b.Get(idx));
                        
                        if (!val)
                        {
                            b.Clear(idx);
                        }
                        Assert.IsTrue(b.Get(idx) == val);
                    }
                }

                // test that the various ways of accessing the bits are equivalent
                DoGet(a, b);
                
                // test ranges, including possible extension
                int fromIndex, toIndex;
                fromIndex = Random().Next(sz / 2);
                toIndex = fromIndex + Random().Next(sz - fromIndex);
                BitArray aa = (BitArray)a.Clone();
                aa.Flip(fromIndex, toIndex);
                LongBitSet bb = b.Clone();
                bb.Flip(fromIndex, toIndex);

                fromIndex = Random().Next(sz / 2);
                toIndex = fromIndex + Random().Next(sz - fromIndex);
                aa = (BitArray)a.Clone();
                aa.Clear(fromIndex, toIndex);
                bb = b.Clone();
                bb.Clear(fromIndex, toIndex);

                DoNextSetBit(aa, bb); // a problem here is from clear() or nextSetBit

                DoPrevSetBit(aa, bb);

                fromIndex = Random().Next(sz / 2);
                toIndex = fromIndex + Random().Next(sz - fromIndex);
                aa = (BitArray)a.Clone();
                aa.Set(fromIndex, toIndex);
                bb = b.Clone();
                bb.Set(fromIndex, toIndex);

                DoNextSetBit(aa, bb); // a problem here is from set() or nextSetBit

                DoPrevSetBit(aa, bb);

                if (b0 != null && b0.Length() <= b.Length())
                {
                    Assert.AreEqual(a.Cardinality(), b.Cardinality());

                    BitArray a_and = (BitArray)a.Clone();
                    a_and = a_and.And_UnequalLengths(a0);
                    BitArray a_or = (BitArray)a.Clone();
                    a_or = a_or.Or_UnequalLengths(a0);
                    BitArray a_xor = (BitArray)a.Clone();
                    a_xor = a_xor.Xor_UnequalLengths(a0);
                    BitArray a_andn = (BitArray)a.Clone();
                    a_andn.AndNot(a0);

                    LongBitSet b_and = b.Clone();
                    Assert.AreEqual(b, b_and);
                    b_and.And(b0);
                    LongBitSet b_or = b.Clone();
                    b_or.Or(b0);
//.........这里部分代码省略.........
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:101,代码来源:TestLongBitSet.cs

示例3: UpdateEntrySet

		private bool UpdateEntrySet(BitArray entrySet, BitArray exitSet, BitArray useBeforeDef, BitArray notDef)
		{
			int card = entrySet.Cardinality();
			entrySet.Or(exitSet);
			entrySet.And(notDef);
			entrySet.Or(useBeforeDef);
			return entrySet.Cardinality() != card;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:8,代码来源:Block.cs


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