Thread: [Nice-commit] Nice/src/mlsub/typing/lowlevel Domain.java,1.3,1.4 BitVector.java,1.7,1.8
Brought to you by:
bonniot
From: <bo...@us...> - 2003-09-06 11:31:15
|
Update of /cvsroot/nice/Nice/src/mlsub/typing/lowlevel In directory sc8-pr-cvs1:/tmp/cvs-serv27986/src/mlsub/typing/lowlevel Modified Files: Domain.java BitVector.java Log Message: Revert mlsub.typing.{BitVector,Domain} to their previous version, as the change provoked a bug during the coverage test for methods on abstract interfaces. Index: Domain.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/lowlevel/Domain.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Domain.java 5 Jul 2003 17:05:23 -0000 1.3 --- Domain.java 6 Sep 2003 11:31:10 -0000 1.4 *************** *** 202,206 **** * Iteration thru the domain elements **/ ! public int getLowestSetBit() { int result = super.getLowestSetBit(); if (result == UNDEFINED_INDEX && containsUnit) { --- 202,206 ---- * Iteration thru the domain elements **/ ! int getFirstBit() { // unused method ??? int result = super.getLowestSetBit(); if (result == UNDEFINED_INDEX && containsUnit) { Index: BitVector.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/lowlevel/BitVector.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** BitVector.java 5 Jul 2003 17:05:23 -0000 1.7 --- BitVector.java 6 Sep 2003 11:31:10 -0000 1.8 *************** *** 25,29 **** @return number of WORDS allocated */ ! final private int length() { if (bits1 == null) --- 25,29 ---- @return number of WORDS allocated */ ! private int length() { if (bits1 == null) *************** *** 36,40 **** * Convert bitIndex to a subscript into the bits[] array. */ ! final private static int subscript(int bitIndex) { return bitIndex >> BITS_PER_UNIT; } --- 36,40 ---- * Convert bitIndex to a subscript into the bits[] array. */ ! private static int subscript(int bitIndex) { return bitIndex >> BITS_PER_UNIT; } *************** *** 42,46 **** * Convert a subscript into the bits[] array to a (maximum) bitIndex. */ ! final private static int bitIndex(int subscript) { return (subscript << BITS_PER_UNIT) + MASK; } --- 42,46 ---- * Convert a subscript into the bits[] array to a (maximum) bitIndex. */ ! private static int bitIndex(int subscript) { return (subscript << BITS_PER_UNIT) + MASK; } *************** *** 50,55 **** */ public BitVector() { ! bits0 = 0L; ! bits1 = null; } --- 50,54 ---- */ public BitVector() { ! this(1 << BITS_PER_UNIT); } *************** *** 87,91 **** * @param nth the 0-origin number of the bit to ensure is there. */ ! final private void ensureCapacity(int nth) { int required = subscript(nth) + 1; /* +1 to get length, not index */ if (required == 1) --- 86,90 ---- * @param nth the 0-origin number of the bit to ensure is there. */ ! private void ensureCapacity(int nth) { int required = subscript(nth) + 1; /* +1 to get length, not index */ if (required == 1) *************** *** 108,134 **** } - final private void ensureChunkCapacity(int required) { - if (required > length()) { - /* Ask for larger of doubled size or required size */ - int request = Math.max(2 * length(), required); - if (bits1 == null) - { - bits1 = new long[request]; - bits1[0] = bits0; - } - else - { - long[] newBits = new long[request]; - System.arraycopy(bits1, 0, newBits, 0, bits1.length); - bits1 = newBits; - } - } - } - /** * Sets a bit. * @param bit the bit to be set */ ! final public void set(int bit) { if (bit < 0) { throw new IndexOutOfBoundsException(Integer.toString(bit)); --- 107,115 ---- } /** * Sets a bit. * @param bit the bit to be set */ ! public void set(int bit) { if (bit < 0) { throw new IndexOutOfBoundsException(Integer.toString(bit)); *************** *** 149,155 **** throw new IndexOutOfBoundsException(Integer.toString(bit)); } ! int sub = subscript(bit); ! if (sub < length()) ! andW(sub, ~(1L << (bit & MASK))); } --- 130,138 ---- throw new IndexOutOfBoundsException(Integer.toString(bit)); } ! ensureCapacity(bit); ! if (bits1 == null) ! bits0 &= ~(1L << bit); // we know that bit <= 64 ! else ! bits1[subscript(bit)] &= ~(1L << (bit & MASK)); } *************** *** 251,255 **** @return bits[i] */ ! final private long getW(int i) { if (bits1 == null) --- 234,238 ---- @return bits[i] */ ! private long getW(int i) { if (bits1 == null) *************** *** 264,268 **** Assumes i is a valid word index. */ ! final private void setW(int i, long w) { if (bits1 == null) --- 247,251 ---- Assumes i is a valid word index. */ ! private void setW(int i, long w) { if (bits1 == null) *************** *** 277,281 **** Assumes i is a valid word index. */ ! final private void andW(int i, long w) { if (bits1 == null) --- 260,264 ---- Assumes i is a valid word index. */ ! private void andW(int i, long w) { if (bits1 == null) *************** *** 290,294 **** Assumes i is a valid word index. */ ! final private void orW(int i, long w) { if (bits1 == null) --- 273,277 ---- Assumes i is a valid word index. */ ! private void orW(int i, long w) { if (bits1 == null) *************** *** 303,307 **** Assumes i is a valid word index. */ ! final private void xorW(int i, long w) { if (bits1 == null) --- 286,290 ---- Assumes i is a valid word index. */ ! private void xorW(int i, long w) { if (bits1 == null) *************** *** 312,318 **** /** * Do this = this & (~set1 | set2) on all bits >= from **/ ! final private void andNotOr(int from, BitVector set1, BitVector set2) { int bitsLength = length(); int set1Length = set1.length(); --- 295,316 ---- /** + * do this = this & (~set) on bits >= from + */ + final public void andNot(int from, BitVector set) { + int n = Math.min(length(), set.length()); + int i = subscript(from); + if (i < n) { + andW(i, ~set.getW(i) & (-1L) << (from & MASK)); + i++; + for (; i < n; i++) { + bits1[i] &= ~set.getW(i); + } + } + } + + /** * Do this = this & (~set1 | set2) on all bits >= from **/ ! final public void andNotOr(int from, BitVector set1, BitVector set2) { int bitsLength = length(); int set1Length = set1.length(); *************** *** 385,391 **** **/ final public void or(BitVector set) { ! int setLength = set.length(); if (setLength > 1) { ! ensureChunkCapacity(setLength); for (int i = setLength; i-- > 0 ;) { bits1[i] |= set.bits1[i]; --- 383,392 ---- **/ final public void or(BitVector set) { ! if (this == set) { ! return; ! } ! int setLength = set.nonZeroLength(); if (setLength > 1) { ! ensureCapacity(bitIndex(setLength-1)); for (int i = setLength; i-- > 0 ;) { bits1[i] |= set.bits1[i]; *************** *** 399,408 **** /** * Do this = this | (set1 & set2) **/ final public void orAnd(BitVector set1, BitVector set2) { int setLength = Math.min(set1.nonZeroLength(),set2.nonZeroLength()); ! if (setLength > 1) { ! ensureChunkCapacity(setLength); } for (int i = setLength; i-- > 0 ;) { --- 400,434 ---- /** + * Do this = this | (set1 & ~set2) + **/ + final public void orNotIn(BitVector set1, BitVector set2) { + if (this == set1) { + return; + } + int set1Length = set1.nonZeroLength(); + int set2Length = set2.length(); + if (set1Length > 0) { + ensureCapacity(bitIndex(set1Length - 1)); // XXX: problem ? + } + for (int i = set1Length; i-- > 0;) { + if (i < set2Length) { + orW(i, set1.getW(i) & ~set2.getW(i)); + } else { + orW(i, set1.getW(i)); + } + } + } + + + /** * Do this = this | (set1 & set2) **/ final public void orAnd(BitVector set1, BitVector set2) { + if (this == set1 || this == set2) { + return; + } int setLength = Math.min(set1.nonZeroLength(),set2.nonZeroLength()); ! if (setLength > 0) { ! ensureCapacity(bitIndex(setLength-1));// this might cause some problem... } for (int i = setLength; i-- > 0 ;) { *************** *** 411,425 **** } /* * If there are some trailing zeros, don't count them * result is greater or equal to 1 */ ! final private int nonZeroLength() { if (bits1 == null) return 1; ! int n = bits1.length-1; ! while (n > 0 && bits1[n] == 0L) { n--; } ! return n+1; } --- 437,467 ---- } + + /* * If there are some trailing zeros, don't count them * result is greater or equal to 1 */ ! private int nonZeroLength() { if (bits1 == null) return 1; ! int n = bits1.length; ! while (n > 1 && bits1[n-1] == 0L) { n--; } ! return n; ! } ! ! ! /** ! * Do this = this ^ set ! **/ ! final public void xor(BitVector set) { ! int setLength = set.length(); ! if (setLength > 0) { ! ensureCapacity(bitIndex(setLength-1)); ! } ! for (int i = setLength; i-- > 0 ;) { ! xorW(i, set.getW(i)); ! } } *************** *** 480,483 **** --- 522,527 ---- } + + /** * Clones the BitVector. *************** *** 569,573 **** } ! final private static /* XXX: work around Symantec JIT bug: comment static */ int chunkLowestSetBit(long chunk) { --- 613,617 ---- } ! private static /* XXX: work around Symantec JIT bug: comment static */ int chunkLowestSetBit(long chunk) { *************** *** 589,593 **** * set is empty. **/ ! public int getLowestSetBit() { if (bits1 == null) { --- 633,637 ---- * set is empty. **/ ! final public int getLowestSetBit() { if (bits1 == null) { *************** *** 656,659 **** --- 700,704 ---- } + /** * Compute the first bit set in this & ~set. *************** *** 699,702 **** --- 744,771 ---- } + final public int getLowestSetBitAndNotIn(BitVector set, BitVector exclude) { + int n = length(); + int setLength = set.length(); + int excludeLength = exclude.length(); + int result = 0; + for (int i = 0; i < n; i++) { + long chunk = getW(i); + if (i < setLength) { + chunk &= set.getW(i); + } else { + return UNDEFINED_INDEX; + } + if (i < excludeLength) { + chunk &= ~exclude.getW(i); + } + if (chunk != 0L) { + return result + chunkLowestSetBit(chunk); + } else { + result += 64; + } + } + return UNDEFINED_INDEX; + } + /** * Return true if this BitVector is included in set *************** *** 733,744 **** **/ public boolean isEmpty() { ! if (bits1 == null) ! return bits0 == 0L; ! ! for (int i = bits1.length; --i>0; ) ! if (bits1[i] != 0L) return false; ! ! return bits1[0] == 0L; } --- 802,812 ---- **/ public boolean isEmpty() { ! int n = length(); ! for (int i = 0; i < n; i++) { ! if (getW(i) != 0L) { return false; ! } ! } ! return true; } *************** *** 805,808 **** --- 873,877 ---- } + /** * Clears the first n bits of this BitVector *************** *** 826,847 **** final public void addProduct(BitMatrix M, BitVector v) { int n = M.size(); ! ensureCapacity(n); for(int i = v.getLowestSetBit(); i >= 0; i = v.getLowestSetBit(i+1)) ! { ! BitVector set = M.getRow(i); ! int setLength = set.nonZeroLength(); ! if (setLength > 1) { ! for (int j = setLength; j-- > 0 ;) ! bits1[j] |= set.bits1[j]; ! } ! else ! { ! orW(0, set.getW(0)); ! } ! } } - } --- 895,911 ---- final public void addProduct(BitMatrix M, BitVector v) { int n = M.size(); ! for(int i = v.getLowestSetBit(); i >= 0; i = v.getLowestSetBit(i+1)) ! or(M.getRow(i)); ! } ! final public void slowaddProduct(BitMatrix M, BitVector v) { ! int n = M.size(); ! for (int i = 0; i < n; i++) { ! if (v.get(i)) { ! or(M.getRow(i)); } + } } } |