diff options
author | buraq <buraq@epfl.ch> | 2004-07-15 13:53:37 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2004-07-15 13:53:37 +0000 |
commit | 0adfa22f7022d6a67757f790d01ef4b3f603db40 (patch) | |
tree | 7ee69d2b7c55835c5d2adc972c24678979519693 /sources/scala/collection/mutable/ResizableBitSet.scala | |
parent | 1982d7c0e560ca4d463bc24fabb3494f97068ba4 (diff) | |
download | scala-0adfa22f7022d6a67757f790d01ef4b3f603db40.tar.gz scala-0adfa22f7022d6a67757f790d01ef4b3f603db40.tar.bz2 scala-0adfa22f7022d6a67757f790d01ef4b3f603db40.zip |
bitset fixes
Diffstat (limited to 'sources/scala/collection/mutable/ResizableBitSet.scala')
-rw-r--r-- | sources/scala/collection/mutable/ResizableBitSet.scala | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/sources/scala/collection/mutable/ResizableBitSet.scala b/sources/scala/collection/mutable/ResizableBitSet.scala index a8379bd6c6..a92184b441 100644 --- a/sources/scala/collection/mutable/ResizableBitSet.scala +++ b/sources/scala/collection/mutable/ResizableBitSet.scala @@ -18,12 +18,14 @@ class ResizableBitSet(initSize: Int) extends scala.collection.BitSet { /** default constructor, initial size of 16 bits */ def this() = this( 16 ); + final def byteSize(size:Int) = { (size >>> 3) + (if( (size & 0x07)!= 0 ) 1 else 0) }; + class ByteArray with ResizableArray[Byte] { - override protected val initialSize: Int = initSize >>> 3; + override protected val initialSize: Int = byteSize( initSize ); override protected var array: Array[Byte] = new Array[Byte](initialSize); /** size of this bitset in nbits */ - def ensureBits(nbits: Int): Unit = ensureSize(nbits >>> 3); + def ensureBits(nbits: Int): Unit = ensureSize( byteSize( nbits )); final def and(j: Int, mask:Int): Unit = { array.update( j, (array(j) & mask).asInstanceOf[Byte] ); @@ -45,23 +47,25 @@ class ResizableBitSet(initSize: Int) extends scala.collection.BitSet { protected val internal = new ByteArray(); /** size of this bitset in nbytes */ - var size: Int = 0; + var size: Int = initSize; /** size of this bitset in nbits */ def ensureSize(nbits: Int): Unit = { internal.ensureBits( nbits ); - size = nbits; + if( size < nbits ) size = nbits; } final def set(i: Int, b: Boolean): Unit = if( b ) set(i) else clear(i); final def set(i: Int): Unit = { + ensureSize(i+1); val j = (i >>> 3); val mask = (1 << (i & 0x07)); internal.or(j, mask); } def clear(i: Int): Unit = { + ensureSize(i+1); val j = (i >>> 3); val mask = (1 << (i & 0x07)); internal.and(j, ~mask); |