From d214dd6c6ca7f409139270cf3b0c80598d07f56e Mon Sep 17 00:00:00 2001 From: buraq Date: Tue, 28 Sep 2004 14:45:33 +0000 Subject: faster equality checking for immutable bitset --- sources/scala/collection/immutable/BitSet.scala | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'sources') diff --git a/sources/scala/collection/immutable/BitSet.scala b/sources/scala/collection/immutable/BitSet.scala index 30cd679395..e0a52c43a0 100644 --- a/sources/scala/collection/immutable/BitSet.scala +++ b/sources/scala/collection/immutable/BitSet.scala @@ -34,6 +34,26 @@ class BitSet(n:Int, ba: Array[Int], copy: Boolean) extends collection.BitSet { else ba; + /** + * Checks if two bitsets are structurally identical. + * + * @return true, iff both bitsets contain the same sequence of elements. + */ + override def equals(that: Any): Boolean = + that.isInstanceOf[BitSet] && + { val other = that.asInstanceOf[BitSet]; + (size == other.size) && ( size == 0 || { + var len = size>>>5; + var i = 0; + var res=true; + while(( i<= len ) && res ) { // 32 x faster equality check + res = array(i) == other.array(i); + i = i + 1; + } + res + }) + } || super.equals(that); + def this(rbs: mutable.BitSet) = { this(rbs.size, rbs.toArray, false); } -- cgit v1.2.3