Esempio n. 1
0
            internal virtual void AddWord(int wordNum, byte word)
            {
                Debug.Assert(wordNum > lastWordNum);
                Debug.Assert(word != 0);

                if (!reverse)
                {
                    if (lastWordNum == -1)
                    {
                        clean = 2 + wordNum; // special case for the 1st sequence
                        dirtyWords.WriteByte(word);
                    }
                    else
                    {
                        switch (wordNum - lastWordNum)
                        {
                        case 1:
                            if (word == 0xFF && (byte)dirtyWords.Bytes[dirtyWords.Length - 1] == 0xFF)
                            {
                                --dirtyWords.Length;
                                WriteSequence();
                                reverse = true;
                                clean   = 2;
                            }
                            else
                            {
                                dirtyWords.WriteByte(word);
                            }
                            break;

                        case 2:
                            dirtyWords.WriteByte(0);
                            dirtyWords.WriteByte(word);
                            break;

                        default:
                            WriteSequence();
                            clean = wordNum - lastWordNum - 1;
                            dirtyWords.WriteByte(word);
                            break;
                        }
                    }
                }
                else
                {
                    Debug.Assert(lastWordNum >= 0);
                    switch (wordNum - lastWordNum)
                    {
                    case 1:
                        if (word == 0xFF)
                        {
                            if (dirtyWords.Length == 0)
                            {
                                ++clean;
                            }
                            else if ((byte)dirtyWords.Bytes[dirtyWords.Length - 1] == 0xFF)
                            {
                                --dirtyWords.Length;
                                WriteSequence();
                                clean = 2;
                            }
                            else
                            {
                                dirtyWords.WriteByte(word);
                            }
                        }
                        else
                        {
                            dirtyWords.WriteByte(word);
                        }
                        break;

                    case 2:
                        dirtyWords.WriteByte(0);
                        dirtyWords.WriteByte(word);
                        break;

                    default:
                        WriteSequence();
                        reverse = false;
                        clean   = wordNum - lastWordNum - 1;
                        dirtyWords.WriteByte(word);
                        break;
                    }
                }
                lastWordNum  = wordNum;
                cardinality += BitUtil.BitCount(word);
            }
Esempio n. 2
0
 /// <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>
 public int Cardinality()
 {
     return((int)BitUtil.Pop_Array(bits, 0, bits.Length));
 }
Esempio n. 3
0
 /// <summary>
 /// Returns the popcount or cardinality of the intersection of the two sets.
 /// Neither set is modified.
 /// </summary>
 public static long IntersectionCount(FixedBitSet a, FixedBitSet b)
 {
     return(BitUtil.Pop_Intersect(a.bits, b.bits, 0, Math.Min(a.numWords, b.numWords)));
 }
Esempio n. 4
0
 /// <summary>
 /// Returns number of set bits.  NOTE: this visits every
 /// long in the backing bits array, and the result is not
 /// internally cached!
 /// </summary>
 public long Cardinality()
 {
     return(BitUtil.Pop_Array(bits, 0, bits.Length));
 }
Esempio n. 5
0
 public static long IntersectionCount(OpenBitSet a, OpenBitSet b)
 {
     return(BitUtil.Pop_Intersect(a.m_bits, b.m_bits, 0, Math.Min(a.m_wlen, b.m_wlen)));
 }
Esempio n. 6
0
 public virtual long Cardinality()
 {
     return(BitUtil.Pop_Array(m_bits, 0, m_wlen));
 }