diff options
author | stenman <stenman@epfl.ch> | 2004-03-22 15:50:45 +0000 |
---|---|---|
committer | stenman <stenman@epfl.ch> | 2004-03-22 15:50:45 +0000 |
commit | 7ad11edbe9a9e722bced0adf7dcd34ef256e4a11 (patch) | |
tree | 0c6b88f20737b147833ebd37780af718ec998a69 | |
parent | ef1bee05f0fb8809b11f8f14a87a9a004aa00367 (diff) | |
download | scala-7ad11edbe9a9e722bced0adf7dcd34ef256e4a11.tar.gz scala-7ad11edbe9a9e722bced0adf7dcd34ef256e4a11.tar.bz2 scala-7ad11edbe9a9e722bced0adf7dcd34ef256e4a11.zip |
Bugfix: fixed filter method to remove elemente ...
Bugfix: fixed filter method to remove elemente when pwd(element) instead
of p(element)
-rw-r--r-- | sources/scala/collection/immutable/Map.scala | 5 | ||||
-rw-r--r-- | sources/scala/collection/immutable/Set.scala | 2 | ||||
-rw-r--r-- | sources/scala/collection/mutable/Map.scala | 4 | ||||
-rw-r--r-- | sources/scala/collection/mutable/Set.scala | 2 |
4 files changed, 6 insertions, 7 deletions
diff --git a/sources/scala/collection/immutable/Map.scala b/sources/scala/collection/immutable/Map.scala index e5874141e6..405e054763 100644 --- a/sources/scala/collection/immutable/Map.scala +++ b/sources/scala/collection/immutable/Map.scala @@ -9,7 +9,6 @@ package scala.collection.immutable; - /** This trait extends the Map interface of collections that unambiguously map * keys to values (i.e. a key is mapped to at least one value). * This trait defines the interface for functional map implementations @@ -106,7 +105,7 @@ trait Map[A, B] with scala.collection.Map[A, B] { def filter(p: (A, B) => Boolean): Map[A, B] = { var res = this; toList foreach { - case Pair(key, value) => if (p(key, value)) { res = res.excl(key); } + case Pair(key, value) => if (!p(key, value)) { res = res.excl(key); } } res; } @@ -147,7 +146,7 @@ trait Map[A, B] with scala.collection.Map[A, B] { false; override def hashCode() = { - elements.foldLeft(0)((hash:Int,E:Object) => hash + E.hashCode()); + elements.foldLeft(0)((hash:Int,pair:Object) => hash + pair.hashCode()); } /** This method controls how a mapping is represented in the string diff --git a/sources/scala/collection/immutable/Set.scala b/sources/scala/collection/immutable/Set.scala index b613c7d86f..8ab45c8d5a 100644 --- a/sources/scala/collection/immutable/Set.scala +++ b/sources/scala/collection/immutable/Set.scala @@ -67,7 +67,7 @@ trait Set[A] with scala.collection.Set[A] { def filter(p: A => Boolean): Set[A] = { var res = this; toList foreach { - elem => if (p(elem)) { res = res - elem; } + elem => if (!p(elem)) { res = res - elem; } } res; } diff --git a/sources/scala/collection/mutable/Map.scala b/sources/scala/collection/mutable/Map.scala index e63107bcfb..b2a8a94f99 100644 --- a/sources/scala/collection/mutable/Map.scala +++ b/sources/scala/collection/mutable/Map.scala @@ -21,7 +21,7 @@ package scala.collection.mutable; trait Map[A, B] with scala.collection.Map[A, B] { /** This method allows one to add a new mapping from <code>key</code> - * to <code>value</code> to the map. If the map contains already a + * to <code>value</code> to the map. If the map already contains a * mapping for <code>key</code>, it will be overridden by this * function. */ @@ -84,7 +84,7 @@ trait Map[A, B] with scala.collection.Map[A, B] { * <code>p</code> returns <code>false</code>. */ def filter(p: (A, B) => Boolean): Unit = toList foreach { - case Pair(key, value) => if (p(key, value)) -=(key); + case Pair(key, value) => if (!p(key, value)) -=(key); } /** The hashCode method always yields an error, since it is not diff --git a/sources/scala/collection/mutable/Set.scala b/sources/scala/collection/mutable/Set.scala index d23452a3f9..47f1d6424a 100644 --- a/sources/scala/collection/mutable/Set.scala +++ b/sources/scala/collection/mutable/Set.scala @@ -62,7 +62,7 @@ trait Set[A] with scala.collection.Set[A] { * which the predicate <code>p</code> yields the value <code>false</code>. */ def filter(p: A => Boolean): Unit = toList foreach { - elem => if (p(elem)) -=(elem); + elem => if (!p(elem)) -=(elem); } /** Removes all elements from the set. After this operation is completed, |