You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by Nicolas <ni...@gmail.com> on 2006/07/11 23:18:05 UTC

BitArray vs BitSet

Hello again,
There is also an other issue I would like to point out, Filter are BitArray
based, unfortunately the current implementation of BitArray doesn't provide
any mean to get its population (ot its 'cardinality' as defined in the Java
Bitsets). Does it make sense to you to replace System.Collection.BitArray by
another implementation that could provide this functionnality ?
Nicolas

Re: BitArray vs BitSet

Posted by Nicolas Brel <ni...@gmail.com>.
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 <dj...@gmail.com> wrote:

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

Re: BitArray vs BitSet

Posted by jxf jxf <dj...@gmail.com>.
can you give me a copy?
thanks

Re: BitArray vs BitSet

Posted by Nicolas <ni...@gmail.com>.
Yes of course. The issue is for .Net only. The point is, in c# the method
Bits(IndexReader reader) returns a BitArray.
BitArray is quite similar to java BitSet excepts that there is no efficient
way to find out how many bits in the BitArray are set to true.
That is to say, there is no equivalent to Java BitSet Cardinality() method.
This functionnality is quite usefull to know how many documents match a
given filter.
I was wondering if anyone would be interested in it. If so I could provide
my own implementation of the BitArray, which mimics
System.Collections.BitArray and only adds a Cardinality getter. Thus we'll
have to modify the signature of the Filter abstract method Bits(IndexReader)
to return it.
Pros: closer to Java BitSet functionnality
Cons: new class to maintain, make even more complex the conversion from Java
to C# ?
Regards,
Nicolas



On 7/12/06, George Aroush <ge...@aroush.net> wrote:
>
> Hi Nicolas,
>
> I am not following this issue; can you elaborate some more about it?  Is
> this an issue for .Net of Lucene only or both?
>
> Regards,
>
> -- George
>
> -----Original Message-----
> From: Nicolas [mailto:nicolas.brel@gmail.com]
> Sent: Tuesday, July 11, 2006 5:18 PM
> To: lucene-net-dev@incubator.apache.org
> Subject: BitArray vs BitSet
>
> Hello again,
> There is also an other issue I would like to point out, Filter are
> BitArray
> based, unfortunately the current implementation of BitArray doesn't
> provide
> any mean to get its population (ot its 'cardinality' as defined in the
> Java
> Bitsets). Does it make sense to you to replace System.Collection.BitArrayby
> another implementation that could provide this functionnality ?
> Nicolas
>
>

RE: BitArray vs BitSet

Posted by George Aroush <ge...@aroush.net>.
Hi Nicolas,

I am not following this issue; can you elaborate some more about it?  Is
this an issue for .Net of Lucene only or both?

Regards,

-- George

-----Original Message-----
From: Nicolas [mailto:nicolas.brel@gmail.com] 
Sent: Tuesday, July 11, 2006 5:18 PM
To: lucene-net-dev@incubator.apache.org
Subject: BitArray vs BitSet

Hello again,
There is also an other issue I would like to point out, Filter are BitArray
based, unfortunately the current implementation of BitArray doesn't provide
any mean to get its population (ot its 'cardinality' as defined in the Java
Bitsets). Does it make sense to you to replace System.Collection.BitArray by
another implementation that could provide this functionnality ?
Nicolas