You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2021/05/02 19:51:14 UTC

[lucenenet] branch master updated (da70e1e -> 807ce0b)

This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git.


    from da70e1e  Lucene.Net.Join: Moved entire namespace to Lucene.Net.Search.Join to match Lucene. Added duplicates of the public types in Lucene.Net.Join and marked them Obsolete and hidden from Intellisense so this is not a breaking change.
     new 2b1fff5  BREAKING: Changed all Cardinality() methods into properties named Cardinality. Types affected: FixedBitSet, Int64BitSet, OpenBitSet, PForDeltaDocIdSet, RandomAccessOrds, WAH8DocIdSet. Added obsolete extension methods for each type in the same namespace as each type, but do note this only works if the namespace is imported at the top of the file.
     new 807ce0b  Lucene.Net.Support: Factored out BitArrayExtensions and replaced all occurrences of BitArray with BitSet. Removed FEATURE_BITARRAY_COPYTO.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Directory.Build.targets                            |   1 -
 src/Lucene.Net.Codecs/Bloom/FuzzySet.cs            |   6 +-
 .../Memory/DirectDocValuesProducer.cs              |   5 +-
 .../SimpleText/SimpleTextFieldsReader.cs           |   2 +-
 .../Index/MultiPassIndexSplitter.cs                |   2 +-
 src/Lucene.Net.Misc/Index/PKIndexSplitter.cs       |   2 +-
 .../Queries/SortedSetSortField.cs                  |   6 +-
 .../Codecs/Asserting/AssertingDocValuesFormat.cs   |   4 +-
 .../Codecs/Asserting/AssertingPostingsFormat.cs    |   4 +-
 .../Index/BasePostingsFormatTestCase.cs            |   2 +-
 .../AllGroupHeadsCollectorTest.cs                  |   2 +-
 .../Highlight/HighlighterPhraseTest.cs             |   2 +-
 src/Lucene.Net.Tests.Join/Support/TestJoinUtil.cs  |   4 +-
 src/Lucene.Net.Tests.Join/TestJoinUtil.cs          |   4 +-
 src/Lucene.Net.Tests.Queries/TermsFilterTest.cs    |  12 +-
 src/Lucene.Net.Tests/Index/TestCodecs.cs           |   2 +-
 src/Lucene.Net.Tests/Index/TestDocCount.cs         |   4 +-
 .../Index/TestTransactionRollback.cs               |   2 +-
 src/Lucene.Net.Tests/Search/TestBooleanOr.cs       |   4 +-
 src/Lucene.Net.Tests/Search/TestFilteredSearch.cs  |   4 +-
 src/Lucene.Net.Tests/Search/TestScorerPerf.cs      |  14 +-
 .../Search/TestTimeLimitingCollector.cs            |   4 +-
 src/Lucene.Net.Tests/Util/TestBytesRefHash.cs      |  27 +-
 src/Lucene.Net.Tests/Util/TestFixedBitSet.cs       |  20 +-
 src/Lucene.Net.Tests/Util/TestLongBitSet.cs        |  85 +++---
 src/Lucene.Net.Tests/Util/TestNumericUtils.cs      |   4 +-
 src/Lucene.Net.Tests/Util/TestOpenBitSet.cs        |  18 +-
 src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs |   4 +-
 src/Lucene.Net.Tests/Util/TestWAH8DocIdSet.cs      |   6 +-
 .../Codecs/Lucene45/Lucene45DocValuesProducer.cs   |   6 +-
 src/Lucene.Net/Codecs/TermsConsumer.cs             |   4 +-
 src/Lucene.Net/Index/CheckIndex.cs                 |  16 +-
 src/Lucene.Net/Index/DocValues.cs                  |   7 +-
 .../Index/FreqProxTermsWriterPerField.cs           |   2 +-
 src/Lucene.Net/Index/RandomAccessOrds.cs           |   8 +-
 src/Lucene.Net/Search/FieldCacheImpl.cs            |   4 +-
 src/Lucene.Net/Search/SloppyPhraseScorer.cs        |   4 +-
 src/Lucene.Net/Support/BitArrayExtensions.cs       | 329 ---------------------
 .../ObsoleteAPI/FixedBitSetExtensions.cs}          |  32 +-
 .../ObsoleteAPI/Int64BitSetExtensions.cs}          |  32 +-
 .../ObsoleteAPI/OpenBitSetExtensions.cs}           |  31 +-
 .../ObsoleteAPI/PForDeltaDocIdSetExtensions.cs}    |  29 +-
 .../ObsoleteAPI/RandomAccessOrdsExtensions.cs}     |  23 +-
 .../ObsoleteAPI/WAH8DocIdSetExtensions.cs}         |  29 +-
 src/Lucene.Net/Util/FixedBitSet.cs                 |   8 +-
 src/Lucene.Net/Util/LongBitSet.cs                  |   8 +-
 src/Lucene.Net/Util/OpenBitSet.cs                  |  15 +-
 src/Lucene.Net/Util/PForDeltaDocIdSet.cs           |   8 +-
 src/Lucene.Net/Util/WAH8DocIdSet.cs                |   8 +-
 49 files changed, 229 insertions(+), 630 deletions(-)
 delete mode 100644 src/Lucene.Net/Support/BitArrayExtensions.cs
 copy src/Lucene.Net/{Util/Mutable/MutableValueDate.cs => Support/ObsoleteAPI/FixedBitSetExtensions.cs} (61%)
 copy src/Lucene.Net/{Util/Mutable/MutableValueDate.cs => Support/ObsoleteAPI/Int64BitSetExtensions.cs} (62%)
 copy src/Lucene.Net/{Util/Mutable/MutableValueDate.cs => Support/ObsoleteAPI/OpenBitSetExtensions.cs} (62%)
 copy src/Lucene.Net/{Util/Mutable/MutableValueDate.cs => Support/ObsoleteAPI/PForDeltaDocIdSetExtensions.cs} (62%)
 copy src/Lucene.Net/{Index/BinaryDocValues.cs => Support/ObsoleteAPI/RandomAccessOrdsExtensions.cs} (63%)
 copy src/Lucene.Net/{Util/Mutable/MutableValueDate.cs => Support/ObsoleteAPI/WAH8DocIdSetExtensions.cs} (62%)

[lucenenet] 02/02: Lucene.Net.Support: Factored out BitArrayExtensions and replaced all occurrences of BitArray with BitSet. Removed FEATURE_BITARRAY_COPYTO.

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 807ce0bed74aae88b553d4b0a38d6b68312890d4
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Mon May 3 02:07:30 2021 +0700

    Lucene.Net.Support: Factored out BitArrayExtensions and replaced all occurrences of BitArray with BitSet. Removed FEATURE_BITARRAY_COPYTO.
---
 Directory.Build.targets                       |   1 -
 src/Lucene.Net.Tests/Search/TestScorerPerf.cs |  14 +-
 src/Lucene.Net.Tests/Util/TestBytesRefHash.cs |  27 +--
 src/Lucene.Net.Tests/Util/TestLongBitSet.cs   |  79 +++----
 src/Lucene.Net/Support/BitArrayExtensions.cs  | 329 --------------------------
 5 files changed, 58 insertions(+), 392 deletions(-)

diff --git a/Directory.Build.targets b/Directory.Build.targets
index d7f22c7..d9ef05e 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -62,7 +62,6 @@
     <DefineConstants>$(DefineConstants);FEATURE_APPDOMAIN_GETASSEMBLIES</DefineConstants>
     <DefineConstants>$(DefineConstants);FEATURE_APPDOMAIN_ISFULLYTRUSTED</DefineConstants>
     <DefineConstants>$(DefineConstants);FEATURE_ASSEMBLY_GETCALLINGASSEMBLY</DefineConstants>
-    <DefineConstants>$(DefineConstants);FEATURE_BITARRAY_COPYTO</DefineConstants>
     <DefineConstants>$(DefineConstants);FEATURE_CULTUREINFO_GETCULTURES</DefineConstants>
     <DefineConstants>$(DefineConstants);FEATURE_DTD_PROCESSING</DefineConstants>
     <DefineConstants>$(DefineConstants);FEATURE_FILESTREAM_LOCK</DefineConstants>
diff --git a/src/Lucene.Net.Tests/Search/TestScorerPerf.cs b/src/Lucene.Net.Tests/Search/TestScorerPerf.cs
index f4184a0..00339b2 100644
--- a/src/Lucene.Net.Tests/Search/TestScorerPerf.cs
+++ b/src/Lucene.Net.Tests/Search/TestScorerPerf.cs
@@ -1,9 +1,7 @@
 using Lucene.Net.Documents;
 using Lucene.Net.Index.Extensions;
-using Lucene.Net.Support;
 using NUnit.Framework;
 using System;
-using System.Collections;
 using Assert = Lucene.Net.TestFramework.Assert;
 using BitSet = J2N.Collections.BitSet;
 using Console = Lucene.Net.Util.SystemConsole;
@@ -275,13 +273,13 @@ namespace Lucene.Net.Search
             {
                 int nClauses = Random.Next(maxClauses - 1) + 2; // min 2 clauses
                 BooleanQuery bq = new BooleanQuery();
-                BitArray termflag = new BitArray(termsInIndex);
+                BitSet termflag = new BitSet(termsInIndex);
                 for (int j = 0; j < nClauses; j++)
                 {
                     int tnum;
                     // don't pick same clause twice
                     tnum = Random.Next(termsInIndex);
-                    if (termflag.SafeGet(tnum))
+                    if (termflag.Get(tnum))
                     {
                         tnum = termflag.NextClearBit(tnum);
                     }
@@ -289,7 +287,7 @@ namespace Lucene.Net.Search
                     {
                         tnum = termflag.NextClearBit(0);
                     }
-                    termflag.SafeSet(tnum, true);
+                    termflag.Set(tnum);
                     Query tq = new TermQuery(terms[tnum]);
                     bq.Add(tq, Occur.MUST);
                 }
@@ -319,13 +317,13 @@ namespace Lucene.Net.Search
                 {
                     int nClauses = Random.Next(maxClauses - 1) + 2; // min 2 clauses
                     BooleanQuery bq = new BooleanQuery();
-                    BitArray termflag = new BitArray(termsInIndex);
+                    BitSet termflag = new BitSet(termsInIndex);
                     for (int j = 0; j < nClauses; j++)
                     {
                         int tnum;
                         // don't pick same clause twice
                         tnum = Random.Next(termsInIndex);
-                        if (termflag.SafeGet(tnum))
+                        if (termflag.Get(tnum))
                         {
                             tnum = termflag.NextClearBit(tnum);
                         }
@@ -333,7 +331,7 @@ namespace Lucene.Net.Search
                         {
                             tnum = termflag.NextClearBit(0);
                         }
-                        termflag.SafeSet(tnum, true);
+                        termflag.Set(tnum);
                         Query tq = new TermQuery(terms[tnum]);
                         bq.Add(tq, Occur.MUST);
                     } // inner
diff --git a/src/Lucene.Net.Tests/Util/TestBytesRefHash.cs b/src/Lucene.Net.Tests/Util/TestBytesRefHash.cs
index 8fbe614..53cae51 100644
--- a/src/Lucene.Net.Tests/Util/TestBytesRefHash.cs
+++ b/src/Lucene.Net.Tests/Util/TestBytesRefHash.cs
@@ -1,11 +1,10 @@
-using Lucene.Net.Support;
-using NUnit.Framework;
+using NUnit.Framework;
+using RandomizedTesting.Generators;
 using System;
-using System.Collections;
 using System.Collections.Generic;
-using JCG = J2N.Collections.Generic;
 using Assert = Lucene.Net.TestFramework.Assert;
-using RandomizedTesting.Generators;
+using BitSet = J2N.Collections.BitSet;
+using JCG = J2N.Collections.Generic;
 
 namespace Lucene.Net.Util
 {
@@ -143,7 +142,7 @@ namespace Lucene.Net.Util
         }
 
         /// <summary>
-        /// Test method for <seealso cref="Lucene.Net.Util.BytesRefHash#compact()"/>.
+        /// Test method for <seealso cref="Lucene.Net.Util.BytesRefHash.Compact()"/>.
         /// </summary>
         [Test]
         public virtual void TestCompact()
@@ -154,7 +153,7 @@ namespace Lucene.Net.Util
             {
                 int numEntries = 0;
                 const int size = 797;
-                BitArray bits = new BitArray(size);
+                BitSet bits = new BitSet(size);
                 for (int i = 0; i < size; i++)
                 {
                     string str;
@@ -166,25 +165,25 @@ namespace Lucene.Net.Util
                     int key = hash.Add(@ref);
                     if (key < 0)
                     {
-                        Assert.IsTrue(bits.SafeGet((-key) - 1));
+                        Assert.IsTrue(bits.Get((-key) - 1));
                     }
                     else
                     {
-                        Assert.IsFalse(bits.SafeGet(key));
-                        bits.SafeSet(key, true);
+                        Assert.IsFalse(bits.Get(key));
+                        bits.Set(key);
                         numEntries++;
                     }
                 }
-                Assert.AreEqual(hash.Count, bits.Cardinality());
-                Assert.AreEqual(numEntries, bits.Cardinality());
+                Assert.AreEqual(hash.Count, bits.Cardinality);
+                Assert.AreEqual(numEntries, bits.Cardinality);
                 Assert.AreEqual(numEntries, hash.Count);
                 int[] compact = hash.Compact();
                 Assert.IsTrue(numEntries < compact.Length);
                 for (int i = 0; i < numEntries; i++)
                 {
-                    bits.SafeSet(compact[i], false);
+                    bits.Clear(compact[i]);
                 }
-                Assert.AreEqual(0, bits.Cardinality());
+                Assert.AreEqual(0, bits.Cardinality);
                 hash.Clear();
                 Assert.AreEqual(0, hash.Count);
                 hash.Reinit();
diff --git a/src/Lucene.Net.Tests/Util/TestLongBitSet.cs b/src/Lucene.Net.Tests/Util/TestLongBitSet.cs
index 7df5fc9..829592e 100644
--- a/src/Lucene.Net.Tests/Util/TestLongBitSet.cs
+++ b/src/Lucene.Net.Tests/Util/TestLongBitSet.cs
@@ -1,10 +1,9 @@
-using System;
-using Lucene.Net.Attributes;
-using Lucene.Net.Support;
+using Lucene.Net.Attributes;
 using NUnit.Framework;
-using System.Collections;
-using Assert = Lucene.Net.TestFramework.Assert;
 using RandomizedTesting.Generators;
+using System;
+using Assert = Lucene.Net.TestFramework.Assert;
+using BitSet = J2N.Collections.BitSet;
 
 namespace Lucene.Net.Util
 {
@@ -28,19 +27,19 @@ namespace Lucene.Net.Util
     [TestFixture]
     public class TestLongBitSet : LuceneTestCase
     {
-        internal virtual void DoGet(BitArray a, Int64BitSet b)
+        internal virtual void DoGet(BitSet a, Int64BitSet b)
         {
             long max = b.Length;
             for (int i = 0; i < max; i++)
             {
-                if (a.SafeGet(i) != b.Get(i))
+                if (a.Get(i) != b.Get(i))
                 {
-                    Assert.Fail("mismatch: BitSet=[" + i + "]=" + a.SafeGet(i));
+                    Assert.Fail("mismatch: BitSet=[" + i + "]=" + a.Get(i));
                 }
             }
         }
 
-        internal virtual void DoNextSetBit(BitArray a, Int64BitSet b)
+        internal virtual void DoNextSetBit(BitSet a, Int64BitSet b)
         {
             int aa = -1;
             long bb = -1;
@@ -52,7 +51,7 @@ namespace Lucene.Net.Util
             } while (aa >= 0);
         }
 
-        internal virtual void DoPrevSetBit(BitArray a, Int64BitSet b)
+        internal virtual void DoPrevSetBit(BitSet a, Int64BitSet b)
         {
             int aa = a.Length + Random.Next(100);
             long bb = aa;
@@ -60,7 +59,7 @@ namespace Lucene.Net.Util
             {
                 //aa = a.PrevSetBit(aa-1);
                 aa--;
-                while ((aa >= 0) && (!a.SafeGet(aa)))
+                while ((aa >= 0) && (!a.Get(aa)))
                 {
                     aa--;
                 }
@@ -86,13 +85,13 @@ namespace Lucene.Net.Util
 
         internal virtual void DoRandomSets(int maxSize, int iter, int mode)
         {
-            BitArray a0 = null;
+            BitSet a0 = null;
             Int64BitSet b0 = null;
 
             for (int i = 0; i < iter; i++)
             {
                 int sz = TestUtil.NextInt32(Random, 2, maxSize);
-                BitArray a = new BitArray(sz);
+                BitSet a = new BitSet(sz);
                 Int64BitSet b = new Int64BitSet(sz);
 
                 // test the various ways of setting bits
@@ -104,19 +103,19 @@ namespace Lucene.Net.Util
                         int idx;
 
                         idx = Random.Next(sz);
-                        a.SafeSet(idx, true);
+                        a.Set(idx);
                         b.Set(idx);
 
                         idx = Random.Next(sz);
-                        a.SafeSet(idx, false);
+                        a.Clear(idx);
                         b.Clear(idx);
 
                         idx = Random.Next(sz);
-                        a.SafeSet(idx, !a.SafeGet(idx));
+                        a.Flip(idx);
                         b.Flip(idx, idx + 1);
 
                         idx = Random.Next(sz);
-                        a.SafeSet(idx, !a.SafeGet(idx));
+                        a.Flip(idx);
                         b.Flip(idx, idx + 1);
                         
                         bool val2 = b.Get(idx);
@@ -139,14 +138,14 @@ namespace Lucene.Net.Util
                 int fromIndex, toIndex;
                 fromIndex = Random.Next(sz / 2);
                 toIndex = fromIndex + Random.Next(sz - fromIndex);
-                BitArray aa =  new BitArray(a);
+                BitSet aa =  (BitSet)a.Clone();
                 aa.Flip(fromIndex, toIndex);
                 Int64BitSet bb = b.Clone();
                 bb.Flip(fromIndex, toIndex);
 
                 fromIndex = Random.Next(sz / 2);
                 toIndex = fromIndex + Random.Next(sz - fromIndex);
-                aa = new BitArray(a);
+                aa = (BitSet)a.Clone();
                 aa.Clear(fromIndex, toIndex);
                 bb = b.Clone();
                 bb.Clear(fromIndex, toIndex);
@@ -157,7 +156,7 @@ namespace Lucene.Net.Util
 
                 fromIndex = Random.Next(sz / 2);
                 toIndex = fromIndex + Random.Next(sz - fromIndex);
-                aa = new BitArray(a);
+                aa = (BitSet)a.Clone();
                 aa.Set(fromIndex, toIndex);
                 bb = b.Clone();
                 bb.Set(fromIndex, toIndex);
@@ -168,15 +167,15 @@ namespace Lucene.Net.Util
 
                 if (b0 != null && b0.Length <= b.Length)
                 {
-                    Assert.AreEqual(a.Cardinality(), b.Cardinality);
-
-                    BitArray a_and = new BitArray(a);
-                    a_and = a_and.And_UnequalLengths(a0);
-                    BitArray a_or = new BitArray(a);
-                    a_or = a_or.Or_UnequalLengths(a0);
-                    BitArray a_xor = new BitArray(a);
-                    a_xor = a_xor.Xor_UnequalLengths(a0);
-                    BitArray a_andn = new BitArray(a);
+                    Assert.AreEqual(a.Cardinality, b.Cardinality);
+
+                    BitSet a_and = (BitSet)a.Clone();
+                    a_and.And(a0);
+                    BitSet a_or = (BitSet)a.Clone();
+                    a_or.Or(a0);
+                    BitSet a_xor = (BitSet)a.Clone();
+                    a_xor.Xor(a0);
+                    BitSet a_andn = (BitSet)a.Clone();
                     a_andn.AndNot(a0);
 
                     Int64BitSet b_and = b.Clone();
@@ -189,13 +188,13 @@ namespace Lucene.Net.Util
                     Int64BitSet b_andn = b.Clone();
                     b_andn.AndNot(b0);
 
-                    Assert.AreEqual(a0.Cardinality(), b0.Cardinality);
-                    Assert.AreEqual(a_or.Cardinality(), b_or.Cardinality);
+                    Assert.AreEqual(a0.Cardinality, b0.Cardinality);
+                    Assert.AreEqual(a_or.Cardinality, b_or.Cardinality);
 
-                    Assert.AreEqual(a_and.Cardinality(), b_and.Cardinality);
-                    Assert.AreEqual(a_or.Cardinality(), b_or.Cardinality);
-                    Assert.AreEqual(a_xor.Cardinality(), b_xor.Cardinality);
-                    Assert.AreEqual(a_andn.Cardinality(), b_andn.Cardinality);
+                    Assert.AreEqual(a_and.Cardinality, b_and.Cardinality);
+                    Assert.AreEqual(a_or.Cardinality, b_or.Cardinality);
+                    Assert.AreEqual(a_xor.Cardinality, b_xor.Cardinality);
+                    Assert.AreEqual(a_andn.Cardinality, b_andn.Cardinality);
                 }
 
                 a0 = a;
@@ -374,12 +373,12 @@ namespace Lucene.Net.Util
             return bs;
         }
 
-        private BitArray MakeBitSet(int[] a)
+        private BitSet MakeBitSet(int[] a)
         {
-            BitArray bs = new BitArray(a.Length);
+            BitSet bs = new BitSet(a.Length);
             foreach (int e in a)
             {
-                bs.SafeSet(e, true);
+                bs.Set(e);
             }
             return bs;
         }
@@ -387,7 +386,7 @@ namespace Lucene.Net.Util
         private void CheckPrevSetBitArray(int[] a, int numBits)
         {
             Int64BitSet obs = MakeLongFixedBitSet(a, numBits);
-            BitArray bs = MakeBitSet(a);
+            BitSet bs = MakeBitSet(a);
             DoPrevSetBit(bs, obs);
         }
 
@@ -402,7 +401,7 @@ namespace Lucene.Net.Util
         private void CheckNextSetBitArray(int[] a, int numBits)
         {
             Int64BitSet obs = MakeLongFixedBitSet(a, numBits);
-            BitArray bs = MakeBitSet(a);
+            BitSet bs = MakeBitSet(a);
             DoNextSetBit(bs, obs);
         }
 
diff --git a/src/Lucene.Net/Support/BitArrayExtensions.cs b/src/Lucene.Net/Support/BitArrayExtensions.cs
deleted file mode 100644
index 8c82a32..0000000
--- a/src/Lucene.Net/Support/BitArrayExtensions.cs
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-using System;
-using System.Collections;
-using Lucene.Net.Util;
-
-namespace Lucene.Net.Support
-{
-    /// <summary>
-    /// This class provides supporting methods of java.util.BitSet
-    /// that are not present in System.Collections.BitArray.
-    /// </summary>
-    internal static class BitArrayExtensions
-    {
-        /// <summary>
-        /// Returns the next set bit at or after index, or -1 if no such bit exists.
-        /// </summary>
-        /// <param name="bitArray"></param>
-        /// <param name="index">the index of bit array at which to start checking</param>
-        /// <returns>the next set bit or -1</returns>
-        public static int NextSetBit(this BitArray bitArray, int index)
-        {
-            while (index < bitArray.Length)
-            {
-                // if index bit is set, return it
-                // otherwise check next index bit
-                if (bitArray.Get(index))
-                    return index;
-                else
-                    index++;
-            }
-            // if no bits are set at or after index, return -1
-            return -1;
-        }
-
-        public static int PrevSetBit(this BitArray bitArray, int index)
-        {
-            while (index >= 0 && index < bitArray.Length)
-            {
-                // if index bit is set, return it
-                // otherwise check previous index bit
-                if (bitArray.SafeGet(index))
-                    return index;
-                index--;
-            }
-            // if no bits are set at or before index, return -1
-            return -1;
-        }
-
-        // Produces a bitwise-and of the two BitArrays without requiring they be the same length
-        public static BitArray And_UnequalLengths(this BitArray bitsA, BitArray bitsB)
-        {
-            //Cycle only through fewest bits neccessary without requiring size equality
-            var maxIdx = Math.Min(bitsA.Length, bitsB.Length);//exclusive
-            var bits = new BitArray(maxIdx);
-            for (int i = 0; i < maxIdx; i++)
-            {
-                bits[i] = bitsA[i] & bitsB[i];
-            }
-            return bits;
-        }
-
-        // Produces a bitwise-or of the two BitArrays without requiring they be the same length
-        public static BitArray Or_UnequalLengths(this BitArray bitsA, BitArray bitsB)
-        {
-            var shorter = bitsA.Length < bitsB.Length ? bitsA : bitsB;
-            var longer = bitsA.Length >= bitsB.Length ? bitsA : bitsB;
-            var bits = new BitArray(longer.Length);
-            for (int i = 0; i < longer.Length; i++)
-            {
-                if (i >= shorter.Length)
-                {
-                    bits[i] = longer[i];
-                }
-                else
-                {
-                    bits[i] = shorter[i] | longer[i];
-                }
-            }
-
-            return bits;
-        }
-
-        // Produces a bitwise-xor of the two BitArrays without requiring they be the same length
-        public static BitArray Xor_UnequalLengths(this BitArray bitsA, BitArray bitsB)
-        {
-            var shorter = bitsA.Length < bitsB.Length ? bitsA : bitsB;
-            var longer = bitsA.Length >= bitsB.Length ? bitsA : bitsB;
-            var bits = new BitArray(longer.Length);
-            for (int i = 0; i < longer.Length; i++)
-            {
-                if (i >= shorter.Length)
-                {
-                    bits[i] = longer[i];
-                }
-                else
-                {
-                    bits[i] = shorter[i] ^ longer[i];
-                }
-            }
-
-            return bits;
-        }
-
-        /// <summary>
-        /// Returns the next un-set bit at or after index, or -1 if no such bit exists.
-        /// </summary>
-        /// <param name="bitArray"></param>
-        /// <param name="index">the index of bit array at which to start checking</param>
-        /// <returns>the next set bit or -1</returns>
-        public static int NextClearBit(this BitArray bitArray, int index)
-        {
-            while (index < bitArray.Length)
-            {
-                // if index bit is not set, return it
-                // otherwise check next index bit
-                if (!bitArray.Get(index))
-                    return index;
-                else
-                    index++;
-            }
-            // if no bits are set at or after index, return -1
-            return -1;
-        }
-
-        /// <summary>
-        /// Returns the number of bits set to <c>true</c> in this <see cref="BitArray"/>.
-        /// </summary>
-        /// <param name="bits">This <see cref="BitArray"/>.</param>
-        /// <returns>The number of bits set to true in this <see cref="BitArray"/>.</returns>
-        public static int Cardinality(this BitArray bits)
-        {
-            if (bits is null)
-                throw new ArgumentNullException(nameof(bits));
-            int count = 0;
-
-#if FEATURE_BITARRAY_COPYTO
-            int bitsLength = bits.Length;
-            int[] ints = new int[(bitsLength >> 5) + 1];
-            int intsLength = ints.Length;
-            int c;
-
-            bits.CopyTo(ints, 0);
-
-            // fix for not truncated bits in last integer that may have been set to true with SetAll()
-            ints[intsLength - 1] &= ~(-1 << (bitsLength % 32));
-
-            for (int i = 0; i < intsLength; i++)
-            {
-                c = ints[i];
-
-                // magic (http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel)
-                unchecked
-                {
-                    c -= (c >> 1) & 0x55555555;
-                    c = (c & 0x33333333) + ((c >> 2) & 0x33333333);
-                    c = ((c + (c >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
-                }
-
-                count += c;
-            }
-#else
-            for (int i = 0; i < bits.Length; i++)
-            {
-                if (bits[i])
-                    count++;
-            }
-#endif
-            return count;
-        }
-
-        /// <summary>
-        /// Sets the bit at the given <paramref name="index"/> to true.
-        /// </summary>
-        /// <param name="bits">The BitArray object.</param>
-        /// <param name="index">The position to set to true.</param>
-        public static void Set(this BitArray bits, int index)
-        {
-            bits.SafeSet(index, true);
-        }
-
-        /// <summary>
-        /// Sets the bit at the given index range to true.
-        /// </summary>
-        /// <param name="bits">The BitArray object.</param>
-        /// <param name="fromIndex">The start of the range to set(inclusive)</param>
-        /// <param name="toIndex">The end of the range to set(exclusive)</param>
-        /// <param name="value">the value to set to the range</param>
-        public static void Set(this BitArray bits, int fromIndex, int toIndex, bool value)
-        {
-            for (int i = fromIndex; i < toIndex; ++i)
-            {
-                bits.SafeSet(i, value);
-            }
-        }
-
-        /// <summary>
-        /// Sets the bit at the given <paramref name="index"/> to false.
-        /// </summary>
-        /// <param name="bits">The BitArray object.</param>
-        /// <param name="index">The position to set to false.</param>
-        public static void Clear(this BitArray bits, int index)
-        {
-            bits.SafeSet(index, false);
-        }
-
-        /// <summary>
-        /// Sets all bits to false
-        /// </summary>
-        /// <param name="bits">The BitArray object.</param>
-        public static void Clear(this BitArray bits)
-        {
-            bits.SetAll(false);
-        }
-
-        //Flip all bits in the desired range, startIdx inclusive to endIdx exclusive
-        public static void Flip(this BitArray bits, int startIdx, int endIdx)
-        {
-            for (int i = startIdx; i < endIdx; i++)
-            {
-                bits[i] = !bits[i];
-            }
-        }
-
-        // Sets all bits in the range to false [startIdx, endIdx)
-        public static void Clear(this BitArray bits, int startIdx, int endIdx)
-        {
-            for (int i = startIdx; i < endIdx; i++)
-            {
-                bits[i] = false;
-            }
-        }
-
-        // Sets all bits in the range to true [startIdx, endIdx)
-        public static void Set(this BitArray bits, int startIdx, int endIdx)
-        {
-            for (int i = startIdx; i < endIdx; i++)
-            {
-                bits[i] = true;
-            }
-        }
-
-        // Emulates the Java BitSet.Get() method.
-        // Prevents exceptions from being thrown when the index is too high.
-        public static bool SafeGet(this BitArray a, int loc)
-        {
-            return loc < a.Length && a.Get(loc);
-        }
-
-        //Emulates the Java BitSet.Set() method. Required to reconcile differences between Java BitSet and C# BitArray
-        public static void SafeSet(this BitArray a, int loc, bool value)
-        {
-            if (loc >= a.Length)
-                a.Length = loc + 1;
-
-            a.Set(loc, value);
-        }
-
-        // Clears all bits in this BitArray that correspond to a set bit in the parameter BitArray
-        public static void AndNot(this BitArray bitsA, BitArray bitsB)
-        {
-            //if (Debugging.AssertsEnabled) Debugging.Assert(bitsA.Length == bitsB.Length, "BitArray lengths are not the same");
-            for (int i = 0; i < bitsA.Length; i++)
-            {
-                //bitsA was longer than bitsB
-                if (i >= bitsB.Length)
-                {
-                    return;
-                }
-                if (bitsA[i] && bitsB[i])
-                {
-                    bitsA[i] = false;
-                }
-            }
-        }
-
-        //Does a deep comparison of two BitArrays
-        public static bool BitWiseEquals(this BitArray bitsA, BitArray bitsB)
-        {
-            if (bitsA == bitsB)
-                return true;
-            if (bitsA.Length != bitsB.Length)
-                return false;
-
-            for (int i = 0; i < bitsA.Length; i++)
-            {
-                if (bitsA[i] != bitsB[i])
-                    return false;
-            }
-
-            return true;
-        }
-
-        //Compares a BitArray with an OpenBitSet
-        public static bool Equal(this BitArray a, OpenBitSet b)
-        {
-            var bitArrayCardinality = a.Cardinality();
-            if (bitArrayCardinality != b.Cardinality)
-                return false;
-
-            for (int i = 0; i < bitArrayCardinality; i++)
-            {
-                if (a.SafeGet(i) != b.Get(i))
-                    return false;
-            }
-
-            return true;
-        }
-    }
-}
\ No newline at end of file

[lucenenet] 01/02: BREAKING: Changed all Cardinality() methods into properties named Cardinality. Types affected: FixedBitSet, Int64BitSet, OpenBitSet, PForDeltaDocIdSet, RandomAccessOrds, WAH8DocIdSet. Added obsolete extension methods for each type in the same namespace as each type, but do note this only works if the namespace is imported at the top of the file.

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 2b1fff5fe5d6b914f3525fa0fc415dd27058a398
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Mon May 3 00:45:26 2021 +0700

    BREAKING: Changed all Cardinality() methods into properties named Cardinality. Types affected: FixedBitSet, Int64BitSet, OpenBitSet, PForDeltaDocIdSet, RandomAccessOrds, WAH8DocIdSet. Added obsolete extension methods for each type in the same namespace as each type, but do note this only works if the namespace is imported at the top of the file.
---
 src/Lucene.Net.Codecs/Bloom/FuzzySet.cs            |  6 ++---
 .../Memory/DirectDocValuesProducer.cs              |  5 +---
 .../SimpleText/SimpleTextFieldsReader.cs           |  2 +-
 .../Index/MultiPassIndexSplitter.cs                |  2 +-
 src/Lucene.Net.Misc/Index/PKIndexSplitter.cs       |  2 +-
 .../Queries/SortedSetSortField.cs                  |  6 ++---
 .../Codecs/Asserting/AssertingDocValuesFormat.cs   |  4 +--
 .../Codecs/Asserting/AssertingPostingsFormat.cs    |  4 +--
 .../Index/BasePostingsFormatTestCase.cs            |  2 +-
 .../AllGroupHeadsCollectorTest.cs                  |  2 +-
 .../Highlight/HighlighterPhraseTest.cs             |  2 +-
 src/Lucene.Net.Tests.Join/Support/TestJoinUtil.cs  |  4 +--
 src/Lucene.Net.Tests.Join/TestJoinUtil.cs          |  4 +--
 src/Lucene.Net.Tests.Queries/TermsFilterTest.cs    | 12 ++++-----
 src/Lucene.Net.Tests/Index/TestCodecs.cs           |  2 +-
 src/Lucene.Net.Tests/Index/TestDocCount.cs         |  4 +--
 .../Index/TestTransactionRollback.cs               |  2 +-
 src/Lucene.Net.Tests/Search/TestBooleanOr.cs       |  4 +--
 src/Lucene.Net.Tests/Search/TestFilteredSearch.cs  |  4 +--
 .../Search/TestTimeLimitingCollector.cs            |  4 +--
 src/Lucene.Net.Tests/Util/TestFixedBitSet.cs       | 20 +++++++--------
 src/Lucene.Net.Tests/Util/TestLongBitSet.cs        | 20 +++++++--------
 src/Lucene.Net.Tests/Util/TestNumericUtils.cs      |  4 +--
 src/Lucene.Net.Tests/Util/TestOpenBitSet.cs        | 18 ++++++-------
 src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs |  4 +--
 src/Lucene.Net.Tests/Util/TestWAH8DocIdSet.cs      |  6 ++---
 .../Codecs/Lucene45/Lucene45DocValuesProducer.cs   |  6 +----
 src/Lucene.Net/Codecs/TermsConsumer.cs             |  4 +--
 src/Lucene.Net/Index/CheckIndex.cs                 | 16 ++++++------
 src/Lucene.Net/Index/DocValues.cs                  |  7 ++---
 .../Index/FreqProxTermsWriterPerField.cs           |  2 +-
 src/Lucene.Net/Index/RandomAccessOrds.cs           |  8 +++---
 src/Lucene.Net/Search/FieldCacheImpl.cs            |  4 +--
 src/Lucene.Net/Search/SloppyPhraseScorer.cs        |  4 +--
 src/Lucene.Net/Support/BitArrayExtensions.cs       |  2 +-
 .../Support/ObsoleteAPI/FixedBitSetExtensions.cs}  | 30 ++++++++++------------
 .../Support/ObsoleteAPI/Int64BitSetExtensions.cs}  | 30 ++++++++++------------
 .../Support/ObsoleteAPI/OpenBitSetExtensions.cs}   | 29 +++++++++------------
 .../ObsoleteAPI/PForDeltaDocIdSetExtensions.cs}    | 27 ++++++++-----------
 .../ObsoleteAPI/RandomAccessOrdsExtensions.cs}     | 29 ++++++++-------------
 .../Support/ObsoleteAPI/WAH8DocIdSetExtensions.cs} | 27 ++++++++-----------
 src/Lucene.Net/Util/FixedBitSet.cs                 |  8 +++---
 src/Lucene.Net/Util/LongBitSet.cs                  |  8 +++---
 src/Lucene.Net/Util/OpenBitSet.cs                  | 15 ++++++-----
 src/Lucene.Net/Util/PForDeltaDocIdSet.cs           |  8 ++----
 src/Lucene.Net/Util/WAH8DocIdSet.cs                |  8 ++----
 46 files changed, 186 insertions(+), 235 deletions(-)

diff --git a/src/Lucene.Net.Codecs/Bloom/FuzzySet.cs b/src/Lucene.Net.Codecs/Bloom/FuzzySet.cs
index 47a5ed5..99ffb0a 100644
--- a/src/Lucene.Net.Codecs/Bloom/FuzzySet.cs
+++ b/src/Lucene.Net.Codecs/Bloom/FuzzySet.cs
@@ -260,7 +260,7 @@ namespace Lucene.Net.Codecs.Bloom
         /// <return>A smaller <see cref="FuzzySet"/> or <c>null</c> if the current set is already over-saturated.</return>
         public virtual FuzzySet Downsize(float targetMaxSaturation)
         {
-            var numBitsSet = _filter.Cardinality();
+            var numBitsSet = _filter.Cardinality;
             FixedBitSet rightSizedBitSet;
             var rightSizedBitSetSize = _bloomSize;
             //Hopefully find a smaller size bitset into which we can project accumulated values while maintaining desired saturation level
@@ -303,7 +303,7 @@ namespace Lucene.Net.Codecs.Bloom
 
         public virtual int GetEstimatedUniqueValues()
         {
-            return GetEstimatedNumberUniqueValuesAllowingForCollisions(_bloomSize, _filter.Cardinality());
+            return GetEstimatedNumberUniqueValuesAllowingForCollisions(_bloomSize, _filter.Cardinality);
         }
 
         /// <summary>
@@ -321,7 +321,7 @@ namespace Lucene.Net.Codecs.Bloom
 
         public virtual float GetSaturation()
         {
-            var numBitsSet = _filter.Cardinality();
+            var numBitsSet = _filter.Cardinality;
             return numBitsSet/(float) _bloomSize;
         }
 
diff --git a/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs b/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
index 9d40f0d..9c97c64 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
@@ -511,10 +511,7 @@ namespace Lucene.Net.Codecs.Memory
                 return ords.Get(ordStart + index);
             }
 
-            public override int Cardinality()
-            {
-                return ordLimit - ordStart;
-            }
+            public override int Cardinality => ordLimit - ordStart;
 
             // Leave lookupTerm to super's binary search
 
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
index 7439c70..86cdee3 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
@@ -632,7 +632,7 @@ namespace Lucene.Net.Codecs.SimpleText
                         _termCount++;
                     }
                 }
-                _docCount = visitedDocs.Cardinality();
+                _docCount = visitedDocs.Cardinality;
                 _fst = b.Finish();
             
             }
diff --git a/src/Lucene.Net.Misc/Index/MultiPassIndexSplitter.cs b/src/Lucene.Net.Misc/Index/MultiPassIndexSplitter.cs
index 37ec4a2..9277420 100644
--- a/src/Lucene.Net.Misc/Index/MultiPassIndexSplitter.cs
+++ b/src/Lucene.Net.Misc/Index/MultiPassIndexSplitter.cs
@@ -284,7 +284,7 @@ namespace Lucene.Net.Index
                 UndeleteAll(); // initialize main bitset
             }
 
-            public override int NumDocs => liveDocs.Cardinality();
+            public override int NumDocs => liveDocs.Cardinality;
 
             public void UndeleteAll()
             {
diff --git a/src/Lucene.Net.Misc/Index/PKIndexSplitter.cs b/src/Lucene.Net.Misc/Index/PKIndexSplitter.cs
index b90a713..07a8a6d 100644
--- a/src/Lucene.Net.Misc/Index/PKIndexSplitter.cs
+++ b/src/Lucene.Net.Misc/Index/PKIndexSplitter.cs
@@ -169,7 +169,7 @@ namespace Lucene.Net.Index
                 }
 
                 this.liveDocs = bits;
-                this.numDocs = bits.Cardinality();
+                this.numDocs = bits.Cardinality;
             }
 
             public override int NumDocs => numDocs;
diff --git a/src/Lucene.Net.Sandbox/Queries/SortedSetSortField.cs b/src/Lucene.Net.Sandbox/Queries/SortedSetSortField.cs
index 40896e4..1253bca 100644
--- a/src/Lucene.Net.Sandbox/Queries/SortedSetSortField.cs
+++ b/src/Lucene.Net.Sandbox/Queries/SortedSetSortField.cs
@@ -243,7 +243,7 @@ namespace Lucene.Net.Sandbox.Queries
             public override int GetOrd(int docID)
             {
                 @in.SetDocument(docID);
-                int count = @in.Cardinality();
+                int count = @in.Cardinality;
                 if (count == 0)
                 {
                     return -1;
@@ -280,7 +280,7 @@ namespace Lucene.Net.Sandbox.Queries
             public override int GetOrd(int docID)
             {
                 @in.SetDocument(docID);
-                int count = @in.Cardinality();
+                int count = @in.Cardinality;
                 if (count == 0)
                 {
                     return -1;
@@ -317,7 +317,7 @@ namespace Lucene.Net.Sandbox.Queries
             public override int GetOrd(int docID)
             {
                 @in.SetDocument(docID);
-                int count = @in.Cardinality();
+                int count = @in.Cardinality;
                 if (count == 0)
                 {
                     return -1;
diff --git a/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingDocValuesFormat.cs b/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingDocValuesFormat.cs
index c27edc6..734d6d5 100644
--- a/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingDocValuesFormat.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingDocValuesFormat.cs
@@ -121,7 +121,7 @@ namespace Lucene.Net.Codecs.Asserting
                 }
 
                 if (Debugging.AssertsEnabled) Debugging.Assert(count == maxDoc);
-                if (Debugging.AssertsEnabled) Debugging.Assert(seenOrds.Cardinality() == valueCount);
+                if (Debugging.AssertsEnabled) Debugging.Assert(seenOrds.Cardinality == valueCount);
                 CheckIterator(values.GetEnumerator(), valueCount, false);
                 CheckIterator(docToOrd.GetEnumerator(), maxDoc, false);
                 @in.AddSortedField(field, values, docToOrd);
@@ -171,7 +171,7 @@ namespace Lucene.Net.Codecs.Asserting
                 if (Debugging.AssertsEnabled) Debugging.Assert(ordIterator.MoveNext() == false);
 
                 if (Debugging.AssertsEnabled) Debugging.Assert(docCount == maxDoc);
-                if (Debugging.AssertsEnabled) Debugging.Assert(seenOrds.Cardinality() == valueCount);
+                if (Debugging.AssertsEnabled) Debugging.Assert(seenOrds.Cardinality == valueCount);
                 CheckIterator(values.GetEnumerator(), valueCount, false);
                 CheckIterator(docToOrdCount.GetEnumerator(), maxDoc, false);
                 CheckIterator(ords.GetEnumerator(), ordCount, false);
diff --git a/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs b/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs
index 92aa125..5c15349 100644
--- a/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs
@@ -1,4 +1,4 @@
-using Lucene.Net.Codecs.Lucene41;
+using Lucene.Net.Codecs.Lucene41;
 using Lucene.Net.Diagnostics;
 using Lucene.Net.Index;
 using Lucene.Net.Util;
@@ -176,7 +176,7 @@ namespace Lucene.Net.Codecs.Asserting
                 if (Debugging.AssertsEnabled) Debugging.Assert(state == TermsConsumerState.INITIAL || state == TermsConsumerState.START && lastPostingsConsumer.docFreq == 0);
                 state = TermsConsumerState.FINISHED;
                 if (Debugging.AssertsEnabled) Debugging.Assert(docCount >= 0);
-                if (Debugging.AssertsEnabled) Debugging.Assert(docCount == visitedDocs.Cardinality());
+                if (Debugging.AssertsEnabled) Debugging.Assert(docCount == visitedDocs.Cardinality);
                 if (Debugging.AssertsEnabled) Debugging.Assert(sumDocFreq >= docCount);
                 if (Debugging.AssertsEnabled) Debugging.Assert(sumDocFreq == this.sumDocFreq);
                 if (fieldInfo.IndexOptions == IndexOptions.DOCS_ONLY)
diff --git a/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs b/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
index 7bb9aaa..253d615 100644
--- a/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
@@ -674,7 +674,7 @@ namespace Lucene.Net.Index
                         sumDF += postings.DocFreq;
                     }
 
-                    termsConsumer.Finish(doFreq ? sumTotalTF : -1, sumDF, seenDocs.Cardinality());
+                    termsConsumer.Finish(doFreq ? sumTotalTF : -1, sumDF, seenDocs.Cardinality);
                 }
 
             }
diff --git a/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs b/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs
index 83cd800..b4fe1c0 100644
--- a/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs
+++ b/src/Lucene.Net.Tests.Grouping/AllGroupHeadsCollectorTest.cs
@@ -454,7 +454,7 @@ namespace Lucene.Net.Search.Grouping
 
         private bool OpenBitSetContains(int[] expectedDocs, FixedBitSet actual, int maxDoc)
         {
-            if (expectedDocs.Length != actual.Cardinality())
+            if (expectedDocs.Length != actual.Cardinality)
             {
                 return false;
             }
diff --git a/src/Lucene.Net.Tests.Highlighter/Highlight/HighlighterPhraseTest.cs b/src/Lucene.Net.Tests.Highlighter/Highlight/HighlighterPhraseTest.cs
index 8bb2ef4..020cfe8 100644
--- a/src/Lucene.Net.Tests.Highlighter/Highlight/HighlighterPhraseTest.cs
+++ b/src/Lucene.Net.Tests.Highlighter/Highlight/HighlighterPhraseTest.cs
@@ -112,7 +112,7 @@ namespace Lucene.Net.Search.Highlight
                 FixedBitSet bitset = new FixedBitSet(indexReader.MaxDoc);
                 indexSearcher.Search(phraseQuery, new ConcurrentSpanCollectorAnonymousClass(this, bitset));
 
-                assertEquals(1, bitset.Cardinality());
+                assertEquals(1, bitset.Cardinality);
                 int maxDoc = indexReader.MaxDoc;
                 Highlighter highlighter = new Highlighter(
                          new SimpleHTMLFormatter(), new SimpleHTMLEncoder(),
diff --git a/src/Lucene.Net.Tests.Join/Support/TestJoinUtil.cs b/src/Lucene.Net.Tests.Join/Support/TestJoinUtil.cs
index e61aff3..dea1ecf 100644
--- a/src/Lucene.Net.Tests.Join/Support/TestJoinUtil.cs
+++ b/src/Lucene.Net.Tests.Join/Support/TestJoinUtil.cs
@@ -472,7 +472,7 @@ namespace Lucene.Net.Tests.Join
                     // Asserting bit set...
                     if (Verbose)
                     {
-                        Console.WriteLine("expected cardinality:" + expectedResult.Cardinality());
+                        Console.WriteLine("expected cardinality:" + expectedResult.Cardinality);
                         DocIdSetIterator iterator = expectedResult.GetIterator();
                         for (int doc = iterator.NextDoc();
                             doc != DocIdSetIterator.NO_MORE_DOCS;
@@ -480,7 +480,7 @@ namespace Lucene.Net.Tests.Join
                         {
                             Console.WriteLine(string.Format("Expected doc[{0}] with id value {1}", doc, indexSearcher.Doc(doc).Get("id")));
                         }
-                        Console.WriteLine("actual cardinality:" + actualResult.Cardinality());
+                        Console.WriteLine("actual cardinality:" + actualResult.Cardinality);
                         iterator = actualResult.GetIterator();
                         for (int doc = iterator.NextDoc();
                             doc != DocIdSetIterator.NO_MORE_DOCS;
diff --git a/src/Lucene.Net.Tests.Join/TestJoinUtil.cs b/src/Lucene.Net.Tests.Join/TestJoinUtil.cs
index 1bcc291..807f090 100644
--- a/src/Lucene.Net.Tests.Join/TestJoinUtil.cs
+++ b/src/Lucene.Net.Tests.Join/TestJoinUtil.cs
@@ -469,7 +469,7 @@ namespace Lucene.Net.Search.Join
                     // Asserting bit set...
                     if (Verbose)
                     {
-                        Console.WriteLine("expected cardinality:" + expectedResult.Cardinality());
+                        Console.WriteLine("expected cardinality:" + expectedResult.Cardinality);
                         DocIdSetIterator iterator = expectedResult.GetIterator();
                         for (int doc = iterator.NextDoc();
                             doc != DocIdSetIterator.NO_MORE_DOCS;
@@ -477,7 +477,7 @@ namespace Lucene.Net.Search.Join
                         {
                             Console.WriteLine(string.Format("Expected doc[{0}] with id value {1}", doc, indexSearcher.Doc(doc).Get("id")));
                         }
-                        Console.WriteLine("actual cardinality:" + actualResult.Cardinality());
+                        Console.WriteLine("actual cardinality:" + actualResult.Cardinality);
                         iterator = actualResult.GetIterator();
                         for (int doc = iterator.NextDoc();
                             doc != DocIdSetIterator.NO_MORE_DOCS;
diff --git a/src/Lucene.Net.Tests.Queries/TermsFilterTest.cs b/src/Lucene.Net.Tests.Queries/TermsFilterTest.cs
index f8c51fd..319e21b 100644
--- a/src/Lucene.Net.Tests.Queries/TermsFilterTest.cs
+++ b/src/Lucene.Net.Tests.Queries/TermsFilterTest.cs
@@ -78,15 +78,15 @@ namespace Lucene.Net.Tests.Queries
 
             terms.Add(new Term(fieldName, "20"));
             bits = (FixedBitSet)TermsFilter(Random.NextBoolean(), terms).GetDocIdSet(context, context.AtomicReader.LiveDocs);
-            assertEquals("Must match 1", 1, bits.Cardinality());
+            assertEquals("Must match 1", 1, bits.Cardinality);
 
             terms.Add(new Term(fieldName, "10"));
             bits = (FixedBitSet)TermsFilter(Random.NextBoolean(), terms).GetDocIdSet(context, context.AtomicReader.LiveDocs);
-            assertEquals("Must match 2", 2, bits.Cardinality());
+            assertEquals("Must match 2", 2, bits.Cardinality);
 
             terms.Add(new Term(fieldName, "00"));
             bits = (FixedBitSet)TermsFilter(Random.NextBoolean(), terms).GetDocIdSet(context, context.AtomicReader.LiveDocs);
-            assertEquals("Must match 2", 2, bits.Cardinality());
+            assertEquals("Must match 2", 2, bits.Cardinality);
 
             reader.Dispose();
             rd.Dispose();
@@ -133,7 +133,7 @@ namespace Lucene.Net.Tests.Queries
                 else
                 {
                     FixedBitSet bits = (FixedBitSet)docIdSet;
-                    assertTrue("Must be >= 0", bits.Cardinality() >= 0);
+                    assertTrue("Must be >= 0", bits.Cardinality >= 0);
                 }
             }
             multi.Dispose();
@@ -178,7 +178,7 @@ namespace Lucene.Net.Tests.Queries
             TermsFilter tf = new TermsFilter(terms);
 
             FixedBitSet bits = (FixedBitSet)tf.GetDocIdSet(context, context.AtomicReader.LiveDocs);
-            assertEquals("Must be num fields - 1 since we skip only one field", num - 1, bits.Cardinality());
+            assertEquals("Must be num fields - 1 since we skip only one field", num - 1, bits.Cardinality);
             reader.Dispose();
             dir.Dispose();
         }
@@ -224,7 +224,7 @@ namespace Lucene.Net.Tests.Queries
             TermsFilter tf = new TermsFilter(terms.ToList());
 
             FixedBitSet bits = (FixedBitSet)tf.GetDocIdSet(context, context.AtomicReader.LiveDocs);
-            assertEquals(context.Reader.NumDocs, bits.Cardinality());
+            assertEquals(context.Reader.NumDocs, bits.Cardinality);
             reader.Dispose();
             dir.Dispose();
         }
diff --git a/src/Lucene.Net.Tests/Index/TestCodecs.cs b/src/Lucene.Net.Tests/Index/TestCodecs.cs
index 5771fbb..25fb066 100644
--- a/src/Lucene.Net.Tests/Index/TestCodecs.cs
+++ b/src/Lucene.Net.Tests/Index/TestCodecs.cs
@@ -179,7 +179,7 @@ namespace Lucene.Net.Index
                     sumDF += term.docs.Length;
                     sumTotalTermCount += term.Write(termsConsumer);
                 }
-                termsConsumer.Finish(omitTF ? -1 : sumTotalTermCount, sumDF, (int)visitedDocs.Cardinality());
+                termsConsumer.Finish(omitTF ? -1 : sumTotalTermCount, sumDF, (int)visitedDocs.Cardinality);
             }
         }
 
diff --git a/src/Lucene.Net.Tests/Index/TestDocCount.cs b/src/Lucene.Net.Tests/Index/TestDocCount.cs
index 415390b..2412bbb 100644
--- a/src/Lucene.Net.Tests/Index/TestDocCount.cs
+++ b/src/Lucene.Net.Tests/Index/TestDocCount.cs
@@ -1,4 +1,4 @@
-using Lucene.Net.Documents;
+using Lucene.Net.Documents;
 using NUnit.Framework;
 using System.Collections.Generic;
 using Assert = Lucene.Net.TestFramework.Assert;
@@ -98,7 +98,7 @@ namespace Lucene.Net.Index
                         visited.Set(de.DocID);
                     }
                 }
-                Assert.AreEqual(visited.Cardinality(), docCount);
+                Assert.AreEqual(visited.Cardinality, docCount);
             }
         }
     }
diff --git a/src/Lucene.Net.Tests/Index/TestTransactionRollback.cs b/src/Lucene.Net.Tests/Index/TestTransactionRollback.cs
index caaee32..aec7cde 100644
--- a/src/Lucene.Net.Tests/Index/TestTransactionRollback.cs
+++ b/src/Lucene.Net.Tests/Index/TestTransactionRollback.cs
@@ -114,7 +114,7 @@ namespace Lucene.Net.Index
                 }
             }
             r.Dispose();
-            Assert.AreEqual(0, expecteds.Cardinality(), "Should have 0 docs remaining ");
+            Assert.AreEqual(0, expecteds.Cardinality, "Should have 0 docs remaining ");
         }
 
         /*
diff --git a/src/Lucene.Net.Tests/Search/TestBooleanOr.cs b/src/Lucene.Net.Tests/Search/TestBooleanOr.cs
index 999caef..257a6f3 100644
--- a/src/Lucene.Net.Tests/Search/TestBooleanOr.cs
+++ b/src/Lucene.Net.Tests/Search/TestBooleanOr.cs
@@ -1,4 +1,4 @@
-using J2N.Threading.Atomic;
+using J2N.Threading.Atomic;
 using Lucene.Net.Documents;
 using NUnit.Framework;
 using Assert = Lucene.Net.TestFramework.Assert;
@@ -217,7 +217,7 @@ namespace Lucene.Net.Search
                 scorer.Score(c, end);
             }
 
-            Assert.AreEqual(docCount, hits.Cardinality());
+            Assert.AreEqual(docCount, hits.Cardinality);
             r.Dispose();
             dir.Dispose();
         }
diff --git a/src/Lucene.Net.Tests/Search/TestFilteredSearch.cs b/src/Lucene.Net.Tests/Search/TestFilteredSearch.cs
index c578f5d..4708cfa 100644
--- a/src/Lucene.Net.Tests/Search/TestFilteredSearch.cs
+++ b/src/Lucene.Net.Tests/Search/TestFilteredSearch.cs
@@ -1,4 +1,4 @@
-using Lucene.Net.Documents;
+using Lucene.Net.Documents;
 using Lucene.Net.Index.Extensions;
 using NUnit.Framework;
 using System;
@@ -108,7 +108,7 @@ namespace Lucene.Net.Search
                         set.Set(docId - docBase);
                     }
                 }
-                return set.Cardinality() == 0 ? null : set;
+                return set.Cardinality == 0 ? null : set;
             }
         }
     }
diff --git a/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs b/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs
index d35dc02..428855b 100644
--- a/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs
+++ b/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs
@@ -335,7 +335,7 @@ namespace Lucene.Net.Search
             {
                 threadArray[i].Join();
             }
-            assertEquals("some threads failed!", N_THREADS, success.Cardinality());
+            assertEquals("some threads failed!", N_THREADS, success.Cardinality);
         }
 
         private class ThreadAnonymousClass : ThreadJob
@@ -386,7 +386,7 @@ namespace Lucene.Net.Search
 
             public int HitCount()
             {
-                return (int) bits.Cardinality();
+                return (int) bits.Cardinality;
             }
 
             public int LastDocCollected => lastDocCollected;
diff --git a/src/Lucene.Net.Tests/Util/TestFixedBitSet.cs b/src/Lucene.Net.Tests/Util/TestFixedBitSet.cs
index faf72bf..297b6a5 100644
--- a/src/Lucene.Net.Tests/Util/TestFixedBitSet.cs
+++ b/src/Lucene.Net.Tests/Util/TestFixedBitSet.cs
@@ -217,7 +217,7 @@ namespace Lucene.Net.Util
 
                 if (b0 != null && b0.Length <= b.Length)
                 {
-                    Assert.AreEqual(a.Cardinality, b.Cardinality());
+                    Assert.AreEqual(a.Cardinality, b.Cardinality);
                     
                     BitSet a_and = (BitSet)a.Clone();
                     a_and.And(a0);
@@ -238,18 +238,18 @@ namespace Lucene.Net.Util
                     FixedBitSet b_andn = b.Clone();
                     b_andn.AndNot(b0);
 
-                    Assert.AreEqual(a0.Cardinality, b0.Cardinality());
-                    Assert.AreEqual(a_or.Cardinality, b_or.Cardinality());
+                    Assert.AreEqual(a0.Cardinality, b0.Cardinality);
+                    Assert.AreEqual(a_or.Cardinality, b_or.Cardinality);
 
                     DoIterate(a_and, b_and, mode);
                     DoIterate(a_or, b_or, mode);
                     DoIterate(a_andn, b_andn, mode);
                     DoIterate(a_xor, b_xor, mode);
 
-                    Assert.AreEqual(a_and.Cardinality, b_and.Cardinality());
-                    Assert.AreEqual(a_or.Cardinality, b_or.Cardinality());
-                    Assert.AreEqual(a_xor.Cardinality, b_xor.Cardinality());
-                    Assert.AreEqual(a_andn.Cardinality, b_andn.Cardinality());
+                    Assert.AreEqual(a_and.Cardinality, b_and.Cardinality);
+                    Assert.AreEqual(a_or.Cardinality, b_or.Cardinality);
+                    Assert.AreEqual(a_xor.Cardinality, b_xor.Cardinality);
+                    Assert.AreEqual(a_andn.Cardinality, b_andn.Cardinality);
                 }
 
                 a0 = a;
@@ -393,13 +393,13 @@ namespace Lucene.Net.Util
                 FixedBitSet b2 = new FixedBitSet(numBits);
                 Assert.IsTrue(b1.Equals(b2));
                 Assert.AreEqual(b1.GetHashCode(), b2.GetHashCode());
-                Assert.AreEqual(0, b1.Cardinality());
+                Assert.AreEqual(0, b1.Cardinality);
                 if (numBits > 0)
                 {
                     b1.Set(0, numBits);
-                    Assert.AreEqual(numBits, b1.Cardinality());
+                    Assert.AreEqual(numBits, b1.Cardinality);
                     b1.Flip(0, numBits);
-                    Assert.AreEqual(0, b1.Cardinality());
+                    Assert.AreEqual(0, b1.Cardinality);
                 }
             }
         }
diff --git a/src/Lucene.Net.Tests/Util/TestLongBitSet.cs b/src/Lucene.Net.Tests/Util/TestLongBitSet.cs
index 15ea4a4..7df5fc9 100644
--- a/src/Lucene.Net.Tests/Util/TestLongBitSet.cs
+++ b/src/Lucene.Net.Tests/Util/TestLongBitSet.cs
@@ -168,7 +168,7 @@ namespace Lucene.Net.Util
 
                 if (b0 != null && b0.Length <= b.Length)
                 {
-                    Assert.AreEqual(a.Cardinality(), b.Cardinality());
+                    Assert.AreEqual(a.Cardinality(), b.Cardinality);
 
                     BitArray a_and = new BitArray(a);
                     a_and = a_and.And_UnequalLengths(a0);
@@ -189,13 +189,13 @@ namespace Lucene.Net.Util
                     Int64BitSet b_andn = b.Clone();
                     b_andn.AndNot(b0);
 
-                    Assert.AreEqual(a0.Cardinality(), b0.Cardinality());
-                    Assert.AreEqual(a_or.Cardinality(), b_or.Cardinality());
+                    Assert.AreEqual(a0.Cardinality(), b0.Cardinality);
+                    Assert.AreEqual(a_or.Cardinality(), b_or.Cardinality);
 
-                    Assert.AreEqual(a_and.Cardinality(), b_and.Cardinality());
-                    Assert.AreEqual(a_or.Cardinality(), b_or.Cardinality());
-                    Assert.AreEqual(a_xor.Cardinality(), b_xor.Cardinality());
-                    Assert.AreEqual(a_andn.Cardinality(), b_andn.Cardinality());
+                    Assert.AreEqual(a_and.Cardinality(), b_and.Cardinality);
+                    Assert.AreEqual(a_or.Cardinality(), b_or.Cardinality);
+                    Assert.AreEqual(a_xor.Cardinality(), b_xor.Cardinality);
+                    Assert.AreEqual(a_andn.Cardinality(), b_andn.Cardinality);
                 }
 
                 a0 = a;
@@ -339,13 +339,13 @@ namespace Lucene.Net.Util
                 Int64BitSet b2 = new Int64BitSet(numBits);
                 Assert.IsTrue(b1.Equals(b2));
                 Assert.AreEqual(b1.GetHashCode(), b2.GetHashCode());
-                Assert.AreEqual(0, b1.Cardinality());
+                Assert.AreEqual(0, b1.Cardinality);
                 if (numBits > 0)
                 {
                     b1.Set(0, numBits);
-                    Assert.AreEqual(numBits, b1.Cardinality());
+                    Assert.AreEqual(numBits, b1.Cardinality);
                     b1.Flip(0, numBits);
-                    Assert.AreEqual(0, b1.Cardinality());
+                    Assert.AreEqual(0, b1.Cardinality);
                 }
             }
         }
diff --git a/src/Lucene.Net.Tests/Util/TestNumericUtils.cs b/src/Lucene.Net.Tests/Util/TestNumericUtils.cs
index 7f3a0ea..15ff123 100644
--- a/src/Lucene.Net.Tests/Util/TestNumericUtils.cs
+++ b/src/Lucene.Net.Tests/Util/TestNumericUtils.cs
@@ -272,7 +272,7 @@ namespace Lucene.Net.Util
             {
                 // after flipping all bits in the range, the cardinality should be zero
                 bits.Flip(0, upper - lower + 1);
-                Assert.AreEqual(0, bits.Cardinality(), "The sub-range concenated should match the whole range");
+                Assert.AreEqual(0, bits.Cardinality, "The sub-range concenated should match the whole range");
             }
         }
 
@@ -465,7 +465,7 @@ namespace Lucene.Net.Util
             {
                 // after flipping all bits in the range, the cardinality should be zero
                 bits.Flip(0, upper - lower + 1);
-                Assert.AreEqual(0, bits.Cardinality(), "The sub-range concenated should match the whole range");
+                Assert.AreEqual(0, bits.Cardinality, "The sub-range concenated should match the whole range");
             }
         }
 
diff --git a/src/Lucene.Net.Tests/Util/TestOpenBitSet.cs b/src/Lucene.Net.Tests/Util/TestOpenBitSet.cs
index 5fcdfb9..2bf549c 100644
--- a/src/Lucene.Net.Tests/Util/TestOpenBitSet.cs
+++ b/src/Lucene.Net.Tests/Util/TestOpenBitSet.cs
@@ -272,7 +272,7 @@ namespace Lucene.Net.Util
                 {
                     Assert.AreEqual(a.Equals(a0), b.Equals(b0));
 
-                    Assert.AreEqual(a.Cardinality, b.Cardinality());
+                    Assert.AreEqual(a.Cardinality, b.Cardinality);
 
                     BitSet a_and = (BitSet)a.Clone();
                     a_and.And(a0);
@@ -298,16 +298,16 @@ namespace Lucene.Net.Util
                     DoIterate(a_xor, b_xor, mode);
                     DoIterate(a_andn, b_andn, mode);
 
-                    Assert.AreEqual(a_and.Cardinality, b_and.Cardinality());
-                    Assert.AreEqual(a_or.Cardinality, b_or.Cardinality());
-                    Assert.AreEqual(a_xor.Cardinality, b_xor.Cardinality());
-                    Assert.AreEqual(a_andn.Cardinality, b_andn.Cardinality());
+                    Assert.AreEqual(a_and.Cardinality, b_and.Cardinality);
+                    Assert.AreEqual(a_or.Cardinality, b_or.Cardinality);
+                    Assert.AreEqual(a_xor.Cardinality, b_xor.Cardinality);
+                    Assert.AreEqual(a_andn.Cardinality, b_andn.Cardinality);
 
                     // test non-mutating popcounts
-                    Assert.AreEqual(b_and.Cardinality(), OpenBitSet.IntersectionCount(b, b0));
-                    Assert.AreEqual(b_or.Cardinality(), OpenBitSet.UnionCount(b, b0));
-                    Assert.AreEqual(b_xor.Cardinality(), OpenBitSet.XorCount(b, b0));
-                    Assert.AreEqual(b_andn.Cardinality(), OpenBitSet.AndNotCount(b, b0));
+                    Assert.AreEqual(b_and.Cardinality, OpenBitSet.IntersectionCount(b, b0));
+                    Assert.AreEqual(b_or.Cardinality, OpenBitSet.UnionCount(b, b0));
+                    Assert.AreEqual(b_xor.Cardinality, OpenBitSet.XorCount(b, b0));
+                    Assert.AreEqual(b_andn.Cardinality, OpenBitSet.AndNotCount(b, b0));
                 }
 
                 a0 = a;
diff --git a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs b/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
index 80ddafe..6732d12 100644
--- a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
+++ b/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
@@ -1,4 +1,4 @@
-using Assert = Lucene.Net.TestFramework.Assert;
+using Assert = Lucene.Net.TestFramework.Assert;
 using BitSet = J2N.Collections.BitSet;
 
 namespace Lucene.Net.Util
@@ -35,7 +35,7 @@ namespace Lucene.Net.Util
         public override void AssertEquals(int numBits, BitSet ds1, PForDeltaDocIdSet ds2)
         {
             base.AssertEquals(numBits, ds1, ds2);
-            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality());
+            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality);
         }
     }
 }
\ No newline at end of file
diff --git a/src/Lucene.Net.Tests/Util/TestWAH8DocIdSet.cs b/src/Lucene.Net.Tests/Util/TestWAH8DocIdSet.cs
index ba1aac6..234912e 100644
--- a/src/Lucene.Net.Tests/Util/TestWAH8DocIdSet.cs
+++ b/src/Lucene.Net.Tests/Util/TestWAH8DocIdSet.cs
@@ -54,13 +54,13 @@ namespace Lucene.Net.Util
         public override void AssertEquals(int numBits, BitSet ds1, WAH8DocIdSet ds2)
         {
             base.AssertEquals(numBits, ds1, ds2);
-            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality());
+            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality);
         }
 
         //public override void AssertEquals(int numBits, OpenBitSet ds1, WAH8DocIdSet ds2)
         //{
         //    base.AssertEquals(numBits, ds1, ds2);
-        //    Assert.AreEqual(ds1.Cardinality(), ds2.Cardinality());
+        //    Assert.AreEqual(ds1.Cardinality, ds2.Cardinality);
         //}
 
         [Test]
@@ -207,7 +207,7 @@ namespace Lucene.Net.Util
                 }
             }
 
-            Assert.AreEqual(ds1.Cardinality(), ds2.Cardinality());
+            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality);
         }
 
         [Test]
diff --git a/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesProducer.cs b/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesProducer.cs
index b13cabf..f0f945d 100644
--- a/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesProducer.cs
+++ b/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesProducer.cs
@@ -802,11 +802,7 @@ namespace Lucene.Net.Codecs.Lucene45
                 return ordinals.Get(startOffset + index);
             }
 
-            [MethodImpl(MethodImplOptions.AggressiveInlining)]
-            public override int Cardinality()
-            {
-                return (int)(endOffset - startOffset);
-            }
+            public override int Cardinality => (int)(endOffset - startOffset);
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
diff --git a/src/Lucene.Net/Codecs/TermsConsumer.cs b/src/Lucene.Net/Codecs/TermsConsumer.cs
index 68199c8..781a510 100644
--- a/src/Lucene.Net/Codecs/TermsConsumer.cs
+++ b/src/Lucene.Net/Codecs/TermsConsumer.cs
@@ -1,4 +1,4 @@
-using Lucene.Net.Diagnostics;
+using Lucene.Net.Diagnostics;
 using Lucene.Net.Index;
 using System.Collections.Generic;
 using System.Diagnostics;
@@ -244,7 +244,7 @@ namespace Lucene.Net.Codecs
                     }
                 }
             }
-            Finish(indexOptions == IndexOptions.DOCS_ONLY ? -1 : sumTotalTermFreq, sumDocFreq, visitedDocs.Cardinality());
+            Finish(indexOptions == IndexOptions.DOCS_ONLY ? -1 : sumTotalTermFreq, sumDocFreq, visitedDocs.Cardinality);
         }
     }
 }
\ No newline at end of file
diff --git a/src/Lucene.Net/Index/CheckIndex.cs b/src/Lucene.Net/Index/CheckIndex.cs
index 05d3069..c8b85f3 100644
--- a/src/Lucene.Net/Index/CheckIndex.cs
+++ b/src/Lucene.Net/Index/CheckIndex.cs
@@ -1481,9 +1481,9 @@ namespace Lucene.Net.Index
                     if (fieldTerms != null)
                     {
                         int v = fieldTerms.DocCount;
-                        if (v != -1 && visitedDocs.Cardinality() != v)
+                        if (v != -1 && visitedDocs.Cardinality != v)
                         {
-                            throw RuntimeException.Create("docCount for field " + field + "=" + v + " != recomputed docCount=" + visitedDocs.Cardinality());
+                            throw RuntimeException.Create("docCount for field " + field + "=" + v + " != recomputed docCount=" + visitedDocs.Cardinality);
                         }
                     }
 
@@ -1849,9 +1849,9 @@ namespace Lucene.Net.Index
             {
                 throw RuntimeException.Create("dv for field: " + fieldName + " reports wrong maxOrd=" + maxOrd + " but this is not the case: " + maxOrd2);
             }
-            if (seenOrds.Cardinality() != dv.ValueCount)
+            if (seenOrds.Cardinality != dv.ValueCount)
             {
-                throw RuntimeException.Create("dv for field: " + fieldName + " has holes in its ords, ValueCount=" + dv.ValueCount + " but only used: " + seenOrds.Cardinality());
+                throw RuntimeException.Create("dv for field: " + fieldName + " has holes in its ords, ValueCount=" + dv.ValueCount + " but only used: " + seenOrds.Cardinality);
             }
             BytesRef lastValue = null;
             BytesRef scratch = new BytesRef();
@@ -1912,7 +1912,7 @@ namespace Lucene.Net.Index
                     }
                     if (dv is RandomAccessOrds randomAccessOrds)
                     {
-                        long ordCount2 = randomAccessOrds.Cardinality();
+                        long ordCount2 = randomAccessOrds.Cardinality;
                         if (ordCount != ordCount2)
                         {
                             throw RuntimeException.Create("cardinality inconsistent, expected=" + ordCount + ",got=" + ordCount2 + " for doc: " + i);
@@ -1928,7 +1928,7 @@ namespace Lucene.Net.Index
                     }
                     if (dv is RandomAccessOrds randomAccessOrds)
                     {
-                        long ordCount2 = randomAccessOrds.Cardinality();
+                        long ordCount2 = randomAccessOrds.Cardinality;
                         if (ordCount2 != 0)
                         {
                             throw RuntimeException.Create("dv for field: " + fieldName + " is marked missing but has cardinality " + ordCount2 + " for doc: " + i);
@@ -1940,9 +1940,9 @@ namespace Lucene.Net.Index
             {
                 throw RuntimeException.Create("dv for field: " + fieldName + " reports wrong maxOrd=" + maxOrd + " but this is not the case: " + maxOrd2);
             }
-            if (seenOrds.Cardinality() != dv.ValueCount)
+            if (seenOrds.Cardinality != dv.ValueCount)
             {
-                throw RuntimeException.Create("dv for field: " + fieldName + " has holes in its ords, valueCount=" + dv.ValueCount + " but only used: " + seenOrds.Cardinality());
+                throw RuntimeException.Create("dv for field: " + fieldName + " has holes in its ords, valueCount=" + dv.ValueCount + " but only used: " + seenOrds.Cardinality);
             }
 
             BytesRef lastValue = null;
diff --git a/src/Lucene.Net/Index/DocValues.cs b/src/Lucene.Net/Index/DocValues.cs
index fa41d10..89b6853 100644
--- a/src/Lucene.Net/Index/DocValues.cs
+++ b/src/Lucene.Net/Index/DocValues.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
 
 namespace Lucene.Net.Index
 {
@@ -127,10 +127,7 @@ namespace Lucene.Net.Index
                 throw new IndexOutOfRangeException();
             }
 
-            public override int Cardinality()
-            {
-                return 0;
-            }
+            public override int Cardinality => 0;
         }
 
         /// <summary>
diff --git a/src/Lucene.Net/Index/FreqProxTermsWriterPerField.cs b/src/Lucene.Net/Index/FreqProxTermsWriterPerField.cs
index 95cb5c6..e51cc32 100644
--- a/src/Lucene.Net/Index/FreqProxTermsWriterPerField.cs
+++ b/src/Lucene.Net/Index/FreqProxTermsWriterPerField.cs
@@ -669,7 +669,7 @@ namespace Lucene.Net.Index
                 sumDocFreq += docFreq;
             }
 
-            termsConsumer.Finish(writeTermFreq ? sumTotalTermFreq : -1, sumDocFreq, visitedDocs.Cardinality());
+            termsConsumer.Finish(writeTermFreq ? sumTotalTermFreq : -1, sumDocFreq, visitedDocs.Cardinality);
         }
     }
 }
\ No newline at end of file
diff --git a/src/Lucene.Net/Index/RandomAccessOrds.cs b/src/Lucene.Net/Index/RandomAccessOrds.cs
index 91b3510..9737c51 100644
--- a/src/Lucene.Net/Index/RandomAccessOrds.cs
+++ b/src/Lucene.Net/Index/RandomAccessOrds.cs
@@ -1,4 +1,4 @@
-namespace Lucene.Net.Index
+namespace Lucene.Net.Index
 {
     /*
      * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -41,7 +41,7 @@ namespace Lucene.Net.Index
         /// Retrieve the ordinal for the current document (previously
         /// set by <see cref="SortedSetDocValues.SetDocument(int)"/> at the specified index.
         /// <para/>
-        /// An index ranges from <c>0</c> to <c>Cardinality()-1</c>.
+        /// An index ranges from <c>0</c> to <c>Cardinality-1</c>.
         /// The first ordinal value is at index <c>0</c>, the next at index <c>1</c>,
         /// and so on, as for array indexing. </summary>
         /// <param name="index"> index of the ordinal for the document. </param>
@@ -49,9 +49,9 @@ namespace Lucene.Net.Index
         public abstract long OrdAt(int index);
 
         /// <summary>
-        /// Returns the cardinality for the current document (previously
+        /// Gets the cardinality for the current document (previously
         /// set by <see cref="SortedSetDocValues.SetDocument(int)"/>.
         /// </summary>
-        public abstract int Cardinality();
+        public abstract int Cardinality { get; }
     }
 }
\ No newline at end of file
diff --git a/src/Lucene.Net/Search/FieldCacheImpl.cs b/src/Lucene.Net/Search/FieldCacheImpl.cs
index c874c19..8a64830 100644
--- a/src/Lucene.Net/Search/FieldCacheImpl.cs
+++ b/src/Lucene.Net/Search/FieldCacheImpl.cs
@@ -540,7 +540,7 @@ namespace Lucene.Net.Search
             }
             else if (docsWithField is FixedBitSet fixedBitSet)
             {
-                int numSet = fixedBitSet.Cardinality();
+                int numSet = fixedBitSet.Cardinality;
                 if (numSet >= maxDoc)
                 {
                     // The cardinality of the BitSet is maxDoc if all documents have a value.
@@ -1197,7 +1197,7 @@ namespace Lucene.Net.Search
                 {
                     return new Lucene.Net.Util.Bits.MatchNoBits(maxDoc);
                 }
-                int numSet = res.Cardinality();
+                int numSet = res.Cardinality;
                 if (numSet >= maxDoc)
                 {
                     // The cardinality of the BitSet is maxDoc if all documents have a value.
diff --git a/src/Lucene.Net/Search/SloppyPhraseScorer.cs b/src/Lucene.Net/Search/SloppyPhraseScorer.cs
index e8fd5f8..9b1caf7 100644
--- a/src/Lucene.Net/Search/SloppyPhraseScorer.cs
+++ b/src/Lucene.Net/Search/SloppyPhraseScorer.cs
@@ -1,4 +1,4 @@
-using J2N.Collections.Generic.Extensions;
+using J2N.Collections.Generic.Extensions;
 using Lucene.Net.Diagnostics;
 using System;
 using System.Collections.Generic;
@@ -193,7 +193,7 @@ namespace Lucene.Net.Search
             int n = 0;
             // TODO would be good if we can avoid calling cardinality() in each iteration!
             int numBits = bits.Length; // larges bit we set
-            while (bits.Cardinality() > 0)
+            while (bits.Cardinality > 0)
             {
                 PhrasePositions pp2 = pq.Pop();
                 rptStack[n++] = pp2;
diff --git a/src/Lucene.Net/Support/BitArrayExtensions.cs b/src/Lucene.Net/Support/BitArrayExtensions.cs
index 31a7859..8c82a32 100644
--- a/src/Lucene.Net/Support/BitArrayExtensions.cs
+++ b/src/Lucene.Net/Support/BitArrayExtensions.cs
@@ -314,7 +314,7 @@ namespace Lucene.Net.Support
         public static bool Equal(this BitArray a, OpenBitSet b)
         {
             var bitArrayCardinality = a.Cardinality();
-            if (bitArrayCardinality != b.Cardinality())
+            if (bitArrayCardinality != b.Cardinality)
                 return false;
 
             for (int i = 0; i < bitArrayCardinality; i++)
diff --git a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs b/src/Lucene.Net/Support/ObsoleteAPI/FixedBitSetExtensions.cs
similarity index 54%
copy from src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
copy to src/Lucene.Net/Support/ObsoleteAPI/FixedBitSetExtensions.cs
index 80ddafe..167d0c5 100644
--- a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
+++ b/src/Lucene.Net/Support/ObsoleteAPI/FixedBitSetExtensions.cs
@@ -1,5 +1,5 @@
-using Assert = Lucene.Net.TestFramework.Assert;
-using BitSet = J2N.Collections.BitSet;
+using System;
+using System.Runtime.CompilerServices;
 
 namespace Lucene.Net.Util
 {
@@ -20,22 +20,18 @@ namespace Lucene.Net.Util
      * limitations under the License.
      */
 
-    public class TestPForDeltaDocIdSet : BaseDocIdSetTestCase<PForDeltaDocIdSet>
+    public static class FixedBitSetExtensions
     {
-        public override PForDeltaDocIdSet CopyOf(BitSet bs, int length)
+        /// <summary>
+        /// Returns number of set bits.  NOTE: this visits every
+        /// <see cref="long"/> in the backing bits array, and the result is not
+        /// internally cached!
+        /// </summary>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        [Obsolete("Use Cardinality property instead. This extension method will be removed in 4.8.0 release candidate."), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
+        public static int Cardinality(this FixedBitSet set)
         {
-            PForDeltaDocIdSet.Builder builder = (new PForDeltaDocIdSet.Builder()).SetIndexInterval(TestUtil.NextInt32(Random, 1, 20));
-            for (int doc = bs.NextSetBit(0); doc != -1; doc = bs.NextSetBit(doc + 1))
-            {
-                builder.Add(doc);
-            }
-            return builder.Build();
-        }
-
-        public override void AssertEquals(int numBits, BitSet ds1, PForDeltaDocIdSet ds2)
-        {
-            base.AssertEquals(numBits, ds1, ds2);
-            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality());
+            return set.Cardinality;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs b/src/Lucene.Net/Support/ObsoleteAPI/Int64BitSetExtensions.cs
similarity index 54%
copy from src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
copy to src/Lucene.Net/Support/ObsoleteAPI/Int64BitSetExtensions.cs
index 80ddafe..92a4ab4 100644
--- a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
+++ b/src/Lucene.Net/Support/ObsoleteAPI/Int64BitSetExtensions.cs
@@ -1,5 +1,5 @@
-using Assert = Lucene.Net.TestFramework.Assert;
-using BitSet = J2N.Collections.BitSet;
+using System;
+using System.Runtime.CompilerServices;
 
 namespace Lucene.Net.Util
 {
@@ -20,22 +20,18 @@ namespace Lucene.Net.Util
      * limitations under the License.
      */
 
-    public class TestPForDeltaDocIdSet : BaseDocIdSetTestCase<PForDeltaDocIdSet>
+    public static class Int64BitSetExtensions
     {
-        public override PForDeltaDocIdSet CopyOf(BitSet bs, int length)
+        /// <summary>
+        /// Returns number of set bits.  NOTE: this visits every
+        /// long in the backing bits array, and the result is not
+        /// internally cached!
+        /// </summary>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        [Obsolete("Use Cardinality property instead. This extension method will be removed in 4.8.0 release candidate."), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
+        public static long Cardinality(this Int64BitSet set)
         {
-            PForDeltaDocIdSet.Builder builder = (new PForDeltaDocIdSet.Builder()).SetIndexInterval(TestUtil.NextInt32(Random, 1, 20));
-            for (int doc = bs.NextSetBit(0); doc != -1; doc = bs.NextSetBit(doc + 1))
-            {
-                builder.Add(doc);
-            }
-            return builder.Build();
-        }
-
-        public override void AssertEquals(int numBits, BitSet ds1, PForDeltaDocIdSet ds2)
-        {
-            base.AssertEquals(numBits, ds1, ds2);
-            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality());
+            return set.Cardinality;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs b/src/Lucene.Net/Support/ObsoleteAPI/OpenBitSetExtensions.cs
similarity index 54%
copy from src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
copy to src/Lucene.Net/Support/ObsoleteAPI/OpenBitSetExtensions.cs
index 80ddafe..c46ebb2 100644
--- a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
+++ b/src/Lucene.Net/Support/ObsoleteAPI/OpenBitSetExtensions.cs
@@ -1,5 +1,5 @@
-using Assert = Lucene.Net.TestFramework.Assert;
-using BitSet = J2N.Collections.BitSet;
+using System;
+using System.Runtime.CompilerServices;
 
 namespace Lucene.Net.Util
 {
@@ -20,22 +20,17 @@ namespace Lucene.Net.Util
      * limitations under the License.
      */
 
-    public class TestPForDeltaDocIdSet : BaseDocIdSetTestCase<PForDeltaDocIdSet>
+    public static class OpenBitSetExtensions
     {
-        public override PForDeltaDocIdSet CopyOf(BitSet bs, int length)
+        /// <summary>
+        /// Get the number of set bits.
+        /// </summary>
+        /// <returns> The number of set bits. </returns>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        [Obsolete("Use Cardinality property instead. This extension method will be removed in 4.8.0 release candidate."), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
+        public static long Cardinality(this OpenBitSet set)
         {
-            PForDeltaDocIdSet.Builder builder = (new PForDeltaDocIdSet.Builder()).SetIndexInterval(TestUtil.NextInt32(Random, 1, 20));
-            for (int doc = bs.NextSetBit(0); doc != -1; doc = bs.NextSetBit(doc + 1))
-            {
-                builder.Add(doc);
-            }
-            return builder.Build();
-        }
-
-        public override void AssertEquals(int numBits, BitSet ds1, PForDeltaDocIdSet ds2)
-        {
-            base.AssertEquals(numBits, ds1, ds2);
-            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality());
+            return set.Cardinality;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs b/src/Lucene.Net/Support/ObsoleteAPI/PForDeltaDocIdSetExtensions.cs
similarity index 54%
copy from src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
copy to src/Lucene.Net/Support/ObsoleteAPI/PForDeltaDocIdSetExtensions.cs
index 80ddafe..ca0976a 100644
--- a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
+++ b/src/Lucene.Net/Support/ObsoleteAPI/PForDeltaDocIdSetExtensions.cs
@@ -1,5 +1,5 @@
-using Assert = Lucene.Net.TestFramework.Assert;
-using BitSet = J2N.Collections.BitSet;
+using System;
+using System.Runtime.CompilerServices;
 
 namespace Lucene.Net.Util
 {
@@ -20,22 +20,15 @@ namespace Lucene.Net.Util
      * limitations under the License.
      */
 
-    public class TestPForDeltaDocIdSet : BaseDocIdSetTestCase<PForDeltaDocIdSet>
+    public static class PForDeltaDocIdSetExtensions
     {
-        public override PForDeltaDocIdSet CopyOf(BitSet bs, int length)
+        /// <summary>
+        /// Return the number of documents in this <see cref="Lucene.Net.Search.DocIdSet"/> in constant time. </summary>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        [Obsolete("Use Cardinality property instead. This extension method will be removed in 4.8.0 release candidate."), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
+        public static int Cardinality(this PForDeltaDocIdSet set)
         {
-            PForDeltaDocIdSet.Builder builder = (new PForDeltaDocIdSet.Builder()).SetIndexInterval(TestUtil.NextInt32(Random, 1, 20));
-            for (int doc = bs.NextSetBit(0); doc != -1; doc = bs.NextSetBit(doc + 1))
-            {
-                builder.Add(doc);
-            }
-            return builder.Build();
-        }
-
-        public override void AssertEquals(int numBits, BitSet ds1, PForDeltaDocIdSet ds2)
-        {
-            base.AssertEquals(numBits, ds1, ds2);
-            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality());
+            return set.Cardinality;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs b/src/Lucene.Net/Support/ObsoleteAPI/RandomAccessOrdsExtensions.cs
similarity index 52%
copy from src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
copy to src/Lucene.Net/Support/ObsoleteAPI/RandomAccessOrdsExtensions.cs
index 80ddafe..24a043d 100644
--- a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
+++ b/src/Lucene.Net/Support/ObsoleteAPI/RandomAccessOrdsExtensions.cs
@@ -1,7 +1,6 @@
-using Assert = Lucene.Net.TestFramework.Assert;
-using BitSet = J2N.Collections.BitSet;
+using System;
 
-namespace Lucene.Net.Util
+namespace Lucene.Net.Index
 {
     /*
      * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,22 +19,16 @@ namespace Lucene.Net.Util
      * limitations under the License.
      */
 
-    public class TestPForDeltaDocIdSet : BaseDocIdSetTestCase<PForDeltaDocIdSet>
+    public static class RandomAccessOrdsExtensions
     {
-        public override PForDeltaDocIdSet CopyOf(BitSet bs, int length)
+        /// <summary>
+        /// Returns the cardinality for the current document (previously
+        /// set by <see cref="SortedSetDocValues.SetDocument(int)"/>.
+        /// </summary>
+        [Obsolete("Use Cardinality property instead. This extension method will be removed in 4.8.0 release candidate."), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
+        public static int Cardinality(this RandomAccessOrds randomAccessOrds)
         {
-            PForDeltaDocIdSet.Builder builder = (new PForDeltaDocIdSet.Builder()).SetIndexInterval(TestUtil.NextInt32(Random, 1, 20));
-            for (int doc = bs.NextSetBit(0); doc != -1; doc = bs.NextSetBit(doc + 1))
-            {
-                builder.Add(doc);
-            }
-            return builder.Build();
-        }
-
-        public override void AssertEquals(int numBits, BitSet ds1, PForDeltaDocIdSet ds2)
-        {
-            base.AssertEquals(numBits, ds1, ds2);
-            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality());
+            return randomAccessOrds.Cardinality;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs b/src/Lucene.Net/Support/ObsoleteAPI/WAH8DocIdSetExtensions.cs
similarity index 54%
copy from src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
copy to src/Lucene.Net/Support/ObsoleteAPI/WAH8DocIdSetExtensions.cs
index 80ddafe..a1138de 100644
--- a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs
+++ b/src/Lucene.Net/Support/ObsoleteAPI/WAH8DocIdSetExtensions.cs
@@ -1,5 +1,5 @@
-using Assert = Lucene.Net.TestFramework.Assert;
-using BitSet = J2N.Collections.BitSet;
+using System;
+using System.Runtime.CompilerServices;
 
 namespace Lucene.Net.Util
 {
@@ -20,22 +20,15 @@ namespace Lucene.Net.Util
      * limitations under the License.
      */
 
-    public class TestPForDeltaDocIdSet : BaseDocIdSetTestCase<PForDeltaDocIdSet>
+    public static class WAH8DocIdSetExtensions
     {
-        public override PForDeltaDocIdSet CopyOf(BitSet bs, int length)
+        /// <summary>
+        /// Return the number of documents in this <see cref="Lucene.Net.Search.DocIdSet"/> in constant time. </summary>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        [Obsolete("Use Cardinality property instead. This extension method will be removed in 4.8.0 release candidate."), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
+        public static int Cardinality(this WAH8DocIdSet set)
         {
-            PForDeltaDocIdSet.Builder builder = (new PForDeltaDocIdSet.Builder()).SetIndexInterval(TestUtil.NextInt32(Random, 1, 20));
-            for (int doc = bs.NextSetBit(0); doc != -1; doc = bs.NextSetBit(doc + 1))
-            {
-                builder.Add(doc);
-            }
-            return builder.Build();
-        }
-
-        public override void AssertEquals(int numBits, BitSet ds1, PForDeltaDocIdSet ds2)
-        {
-            base.AssertEquals(numBits, ds1, ds2);
-            Assert.AreEqual(ds1.Cardinality, ds2.Cardinality());
+            return set.Cardinality;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net/Util/FixedBitSet.cs b/src/Lucene.Net/Util/FixedBitSet.cs
index e6013e1..bbad7e9 100644
--- a/src/Lucene.Net/Util/FixedBitSet.cs
+++ b/src/Lucene.Net/Util/FixedBitSet.cs
@@ -252,14 +252,14 @@ namespace Lucene.Net.Util
         }
 
         /// <summary>
-        /// Returns number of set bits.  NOTE: this visits every
+        /// Gets the number of set bits.  NOTE: this visits every
         /// <see cref="long"/> in the backing bits array, and the result is not
         /// internally cached!
         /// </summary>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public int Cardinality()
+        public int Cardinality
         {
-            return (int)BitUtil.Pop_Array(bits, 0, bits.Length);
+            [MethodImpl(MethodImplOptions.AggressiveInlining)]
+            get => (int)BitUtil.Pop_Array(bits, 0, bits.Length);
         }
 
         public bool Get(int index)
diff --git a/src/Lucene.Net/Util/LongBitSet.cs b/src/Lucene.Net/Util/LongBitSet.cs
index ca87789..ba8b9fa 100644
--- a/src/Lucene.Net/Util/LongBitSet.cs
+++ b/src/Lucene.Net/Util/LongBitSet.cs
@@ -113,14 +113,14 @@ namespace Lucene.Net.Util
         }
 
         /// <summary>
-        /// Returns number of set bits.  NOTE: this visits every
+        /// Gets the number of set bits.  NOTE: this visits every
         /// long in the backing bits array, and the result is not
         /// internally cached!
         /// </summary>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public long Cardinality()
+        public long Cardinality
         {
-            return BitUtil.Pop_Array(bits, 0, bits.Length);
+            [MethodImpl(MethodImplOptions.AggressiveInlining)]
+            get => BitUtil.Pop_Array(bits, 0, bits.Length);
         }
 
         public bool Get(long index)
diff --git a/src/Lucene.Net/Util/OpenBitSet.cs b/src/Lucene.Net/Util/OpenBitSet.cs
index 5f6b333..bcc712e 100644
--- a/src/Lucene.Net/Util/OpenBitSet.cs
+++ b/src/Lucene.Net/Util/OpenBitSet.cs
@@ -153,15 +153,17 @@ namespace Lucene.Net.Util
         //}
 
         /// <summary>
-        /// Returns the current capacity of this set. This is *not* equal to <see cref="Cardinality()"/>.
+        /// Returns the current capacity of this set. This is *not* equal to <see cref="Cardinality"/>.
         /// <para/>
         /// NOTE: This is equivalent to size() or length() in Lucene.
         /// </summary>
         public virtual int Length => m_bits.Length << 6;
 
+        int IBits.Length => Length;
+
         /// <summary>
         /// Returns <c>true</c> if there are no set bits </summary>
-        public virtual bool IsEmpty => Cardinality() == 0;
+        public virtual bool IsEmpty => Cardinality == 0;
 
         /// <summary>
         /// Expert: returns the <see cref="T:long[]"/> storing the bits. </summary>
@@ -647,15 +649,16 @@ namespace Lucene.Net.Util
         */
 
         /// <summary>
-        /// Get the number of set bits.
+        /// Gets the number of set bits.
         /// </summary>
         /// <returns> The number of set bits. </returns>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public virtual long Cardinality()
+        public virtual long Cardinality
         {
-            return BitUtil.Pop_Array(m_bits, 0, m_wlen);
+            [MethodImpl(MethodImplOptions.AggressiveInlining)]
+            get => BitUtil.Pop_Array(m_bits, 0, m_wlen);
         }
 
+
         /// <summary>
         /// Returns the popcount or cardinality of the intersection of the two sets.
         /// Neither set is modified.
diff --git a/src/Lucene.Net/Util/PForDeltaDocIdSet.cs b/src/Lucene.Net/Util/PForDeltaDocIdSet.cs
index 3708e30..c9d4d30 100644
--- a/src/Lucene.Net/Util/PForDeltaDocIdSet.cs
+++ b/src/Lucene.Net/Util/PForDeltaDocIdSet.cs
@@ -616,12 +616,8 @@ namespace Lucene.Net.Util
         }
 
         /// <summary>
-        /// Return the number of documents in this <see cref="DocIdSet"/> in constant time. </summary>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public int Cardinality()
-        {
-            return cardinality;
-        }
+        /// Gets the number of documents in this <see cref="DocIdSet"/> in constant time. </summary>
+        public int Cardinality => cardinality;
 
         /// <summary>
         /// Return the memory usage of this instance. </summary>
diff --git a/src/Lucene.Net/Util/WAH8DocIdSet.cs b/src/Lucene.Net/Util/WAH8DocIdSet.cs
index ab832b9..5b953cf 100644
--- a/src/Lucene.Net/Util/WAH8DocIdSet.cs
+++ b/src/Lucene.Net/Util/WAH8DocIdSet.cs
@@ -905,12 +905,8 @@ namespace Lucene.Net.Util
         }
 
         /// <summary>
-        /// Return the number of documents in this <see cref="DocIdSet"/> in constant time. </summary>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public int Cardinality()
-        {
-            return cardinality;
-        }
+        /// Gets the number of documents in this <see cref="DocIdSet"/> in constant time. </summary>
+        public int Cardinality => cardinality;
 
         /// <summary>
         /// Return the memory usage of this class in bytes. </summary>