summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-09-28 14:45:33 +0000
committerburaq <buraq@epfl.ch>2004-09-28 14:45:33 +0000
commitd214dd6c6ca7f409139270cf3b0c80598d07f56e (patch)
tree39d9f93ab702816b9baadde6551624c8e31d4f03 /sources
parente5d611e411a045a496e1500a3a441a77d80e6340 (diff)
downloadscala-d214dd6c6ca7f409139270cf3b0c80598d07f56e.tar.gz
scala-d214dd6c6ca7f409139270cf3b0c80598d07f56e.tar.bz2
scala-d214dd6c6ca7f409139270cf3b0c80598d07f56e.zip
faster equality checking for immutable bitset
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/collection/immutable/BitSet.scala20
1 files changed, 20 insertions, 0 deletions
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);
}