lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicolas Brel" <nicolas.b...@gmail.com>
Subject Re: BitArray vs BitSet
Date Fri, 14 Jul 2006 15:10:37 GMT
Just google "BitArray.cs" and you'll find loads of implementations
I've just added the following code:

        public int Cardinality
        {
            get
            {
                if (_count == -1)
                {
                    _count = 0;
                    for (int i = 0; i < _array.Length; i++)
                    {
                        _count += _bitsSetArray256[(uint)(_array[i]) & 0xff]
+
                        _bitsSetArray256[((uint)(_array[i]) >> 8) & 0xff] +
                        _bitsSetArray256[((uint)(_array[i]) >> 16) & 0xff] +
                        _bitsSetArray256[((uint)_array[i]) >> 24];
                    }
                }
                return _count;
            }
        }


where _array is the backbone of the BitArray, and  _bitsSetArray256 is
define as follows:

static readonly byte[] _bitsSetArray256 =
        {
          0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
          1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
          1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
          2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
          1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
          2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
          2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
          3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
          1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
          2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
          2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
          3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
          2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
          3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
          3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
          4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
        };

Hope it helps...

On 7/13/06, jxf jxf <djsoft.net@gmail.com> wrote:

> can you give me a copy?
> thanks
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message