Pop_array() public static méthode

Returns the number of set bits in an array of longs.
public static Pop_array ( long A, int wordOffset, int numWords ) : long
A long
wordOffset int
numWords int
Résultat long
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.bits, b.bits, 0, Math.Min(a.Wlen, b.Wlen));

            if (a.Wlen > b.Wlen)
            {
                tot += BitUtil.Pop_array(a.bits, b.Wlen, a.Wlen - b.Wlen);
            }
            return(tot);
        }
        /// <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.internalbits, b.internalbits, 0, System.Math.Min(a.wlen, b.wlen));

            if (a.wlen > b.wlen)
            {
                tot += BitUtil.Pop_array(a.internalbits, b.wlen, a.wlen - b.wlen);
            }
            return(tot);
        }
Exemple #3
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 #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.bits, b.bits, 0, Math.Min(a.Wlen, b.Wlen));

            if (a.Wlen < b.Wlen)
            {
                tot += BitUtil.Pop_array(b.bits, a.Wlen, b.Wlen - a.Wlen);
            }
            else if (a.Wlen > b.Wlen)
            {
                tot += BitUtil.Pop_array(a.bits, b.Wlen, a.Wlen - b.Wlen);
            }
            return(tot);
        }
Exemple #5
0
        /// <summary>Returns the popcount or cardinality of the union of the two sets.
        /// Neither set is modified.
        /// </summary>
        public static long UnionCount(OpenBitSet a, OpenBitSet b)
        {
            long tot = BitUtil.Pop_union(a.bits, b.bits, 0, System.Math.Min(a.wlen, b.wlen));

            if (a.wlen < b.wlen)
            {
                tot += BitUtil.Pop_array(b.bits, a.wlen, b.wlen - a.wlen);
            }
            else if (a.wlen > b.wlen)
            {
                tot += BitUtil.Pop_array(a.bits, b.wlen, a.wlen - b.wlen);
            }
            return(tot);
        }
Exemple #6
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 #7
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));
 }
Exemple #8
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);
         + }
         */

        /// <returns> the number of set bits </returns>
        public virtual long Cardinality()
        {
            return(BitUtil.Pop_array(bits, 0, Wlen));
        }
        /*
         * 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);
         +
         + }
         */


        /// <returns> the number of set bits
        /// </returns>
        public virtual long Cardinality()
        {
            return(BitUtil.Pop_array(internalbits, 0, wlen));
        }
Exemple #10
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 int Cardinality()
 {
     return((int)BitUtil.Pop_array(bits, 0, bits.Length));
 }