/* * 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)); }
/// <summary>Returns the popcount or cardinality of the intersection of the two sets. /// Neither set is modified. /// </summary> public static long IntersectionCount(OpenBitSet a, OpenBitSet b) { return(BitUtil.Pop_intersect(a.bits, b.bits, 0, System.Math.Min(a.wlen, b.wlen))); }
/// <summary> /// Returns the popcount or cardinality of the intersection of the two sets. /// Neither set is modified. /// </summary> 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))); }
internal virtual void AddWord(int wordNum, byte word) { if (Debugging.AssertsEnabled) { Debugging.Assert(wordNum > lastWordNum); Debugging.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 { if (Debugging.AssertsEnabled) { Debugging.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); }
/// <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)); }
/* * 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)); }
/// <param name="tableSize"> Size of the hash table, should be a power of two. /// </param> /// <param name="maxChainLength"> Maximum length of each bucket, after which the oldest item inserted is dropped. /// </param> public SimpleStringInterner(int tableSize, int maxChainLength) { cache = new Entry[System.Math.Max(1, BitUtil.NextHighestPowerOfTwo(tableSize))]; this.maxChainLength = System.Math.Max(2, maxChainLength); }
/// <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)); }
/// <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))); }
/* * 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); + + } */ /** @return the number of set bits */ public long Cardinality() { return(BitUtil.pop_array(bits, 0, wlen)); }
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((sbyte)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((sbyte)0); DirtyWords.WriteByte(word); break; default: WriteSequence(); Reverse = false; Clean = wordNum - LastWordNum - 1; DirtyWords.WriteByte(word); break; } } LastWordNum = wordNum; Cardinality += BitUtil.BitCount(word); }