Exemple #1
0
        /// <summary>
        /// Returns the popcount or cardinality of "a and not b"
        /// or "intersection(a, not(b))".
        /// Neither set is modified.
        /// </summary>
        public static long AndNotCount(OpenBitSet a, OpenBitSet b)
        {
            long tot = BitUtil.Pop_AndNot(a.m_bits, b.m_bits, 0, Math.Min(a.m_wlen, b.m_wlen));

            if (a.m_wlen > b.m_wlen)
            {
                tot += BitUtil.Pop_Array(a.m_bits, b.m_wlen, a.m_wlen - b.m_wlen);
            }
            return(tot);
        }
Exemple #2
0
        /// <summary>
        /// Returns the popcount or cardinality of "a and not b" or
        /// "intersection(a, not(b))". Neither set is modified.
        /// </summary>
        public static long AndNotCount(FixedBitSet a, FixedBitSet b)
        {
            long tot = BitUtil.Pop_AndNot(a.bits, b.bits, 0, Math.Min(a.numWords, b.numWords));

            if (a.numWords > b.numWords)
            {
                tot += BitUtil.Pop_Array(a.bits, b.numWords, a.numWords - b.numWords);
            }
            return(tot);
        }
Exemple #3
0
        /// <summary>
        /// Returns the popcount or cardinality of the union of the two sets. Neither
        /// set is modified.
        /// </summary>
        public static long UnionCount(FixedBitSet a, FixedBitSet b)
        {
            long tot = BitUtil.Pop_Union(a.bits, b.bits, 0, Math.Min(a.numWords, b.numWords));

            if (a.numWords < b.numWords)
            {
                tot += BitUtil.Pop_Array(b.bits, a.numWords, b.numWords - a.numWords);
            }
            else if (a.numWords > b.numWords)
            {
                tot += BitUtil.Pop_Array(a.bits, b.numWords, a.numWords - b.numWords);
            }
            return(tot);
        }
Exemple #4
0
        /// <summary>
        /// Returns the popcount or cardinality of the exclusive-or of the two sets.
        /// Neither set is modified.
        /// </summary>
        public static long XorCount(OpenBitSet a, OpenBitSet b)
        {
            long tot = BitUtil.Pop_Xor(a.m_bits, b.m_bits, 0, Math.Min(a.m_wlen, b.m_wlen));

            if (a.m_wlen < b.m_wlen)
            {
                tot += BitUtil.Pop_Array(b.m_bits, a.m_wlen, b.m_wlen - a.m_wlen);
            }
            else if (a.m_wlen > b.m_wlen)
            {
                tot += BitUtil.Pop_Array(a.m_bits, b.m_wlen, a.m_wlen - b.m_wlen);
            }
            return(tot);
        }
Exemple #5
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));
 }
Exemple #6
0
        /*
         * public static int pop(long v0, long v1, long v2, long v3) {
         * // derived from pop_array by setting last four elems to 0.
         * // exchanges one pop() call for 10 elementary operations
         * // saving about 7 instructions... is there a better way?
         *  long twosA=v0 & v1;
         *  long ones=v0^v1;
         *
         *  long u2=ones^v2;
         *  long twosB =(ones&v2)|(u2&v3);
         *  ones=u2^v3;
         *
         *  long fours=(twosA&twosB);
         *  long twos=twosA^twosB;
         *
         *  return (pop(fours)<<2)
         + (pop(twos)<<1)
         + pop(ones);
         + }
         */

        /// <summary>
        /// Get the number of set bits.
        /// </summary>
        /// <returns> The number of set bits. </returns>
        public virtual long Cardinality()
        {
            return(BitUtil.Pop_Array(m_bits, 0, m_wlen));
        }
Exemple #7
0
 public long Cardinality()
 {
     return(BitUtil.Pop_Array(bits, 0, bits.Length));
 }