summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-01-04 16:30:16 +0000
committerMartin Odersky <odersky@gmail.com>2007-01-04 16:30:16 +0000
commit29da7050a8c603778dd7ec9f0b2c617812e00400 (patch)
tree5c49ed4fe91f6cf723f68cdb1f0ce6853248c74e /src
parent78d2e50495215b8c451660e6804ddc8c264446b4 (diff)
downloadscala-29da7050a8c603778dd7ec9f0b2c617812e00400.tar.gz
scala-29da7050a8c603778dd7ec9f0b2c617812e00400.tar.bz2
scala-29da7050a8c603778dd7ec9f0b2c617812e00400.zip
another change to collection libraries
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/Iterable.scala7
-rw-r--r--src/library/scala/Iterator.scala9
-rw-r--r--src/library/scala/Predef.scala2
-rw-r--r--src/library/scala/Seq.scala7
-rw-r--r--src/library/scala/collection/Map.scala2
-rw-r--r--src/library/scala/collection/immutable/ListMap.scala2
-rw-r--r--src/library/scala/collection/immutable/ListSet.scala2
-rw-r--r--src/library/scala/collection/immutable/Map.scala11
-rw-r--r--src/library/scala/collection/immutable/Set.scala10
-rw-r--r--src/library/scala/collection/immutable/TreeMap.scala2
-rw-r--r--src/library/scala/collection/immutable/TreeSet.scala4
-rwxr-xr-xsrc/library/scala/collection/immutable/UnbalancedTreeMap.scala10
-rw-r--r--src/library/scala/collection/mutable/DefaultMapModel.scala2
-rw-r--r--src/library/scala/collection/mutable/HashMap.scala12
-rw-r--r--src/library/scala/collection/mutable/HashSet.scala13
-rw-r--r--src/library/scala/collection/mutable/Map.scala16
-rw-r--r--src/library/scala/collection/mutable/Set.scala12
17 files changed, 112 insertions, 11 deletions
diff --git a/src/library/scala/Iterable.scala b/src/library/scala/Iterable.scala
index 7accb35f6c..d33cff3765 100644
--- a/src/library/scala/Iterable.scala
+++ b/src/library/scala/Iterable.scala
@@ -91,14 +91,19 @@ trait Iterable[+A] {
/** Appends two iterable objects
*
* @return the new iterable object
+ * @deprecated use <code>++</code> instead
*/
- def concat [B >: A](that: Iterable[B]): Iterable[B] = {
+ [deprecated] def concat [B >: A](that: Iterable[B]): Iterable[B] = {
val buf = new ArrayBuffer[B]
this copyToBuffer buf
that copyToBuffer buf
buf
}
+ /** Appends two iterable objects
+ *
+ * @return the new iterable object
+ */
def ++ [B >: A](that: Iterable[B]): Iterable[B] = {
val buf = new ArrayBuffer[B]
this copyToBuffer buf
diff --git a/src/library/scala/Iterator.scala b/src/library/scala/Iterator.scala
index e8fb2d4f05..4fccc09201 100644
--- a/src/library/scala/Iterator.scala
+++ b/src/library/scala/Iterator.scala
@@ -248,12 +248,21 @@ trait Iterator[+A] {
/** Returns a new iterator that first yields the elements of this
* iterator followed by the elements provided by iterator <code>that</code>.
+ * @deprecated use <code>++</code>
*/
def append[B >: A](that: Iterator[B]) = new Iterator[B] {
def hasNext = Iterator.this.hasNext || that.hasNext
def next = if (Iterator.this.hasNext) Iterator.this.next else that.next
}
+ /** Returns a new iterator that first yields the elements of this
+ * iterator followed by the elements provided by iterator <code>that</code>.
+ */
+ def ++[B >: A](that: Iterator[B]) = new Iterator[B] {
+ def hasNext = Iterator.this.hasNext || that.hasNext
+ def next = if (Iterator.this.hasNext) Iterator.this.next else that.next
+ }
+
/** Applies the given function <code>f</code> to each element of
* this iterator, then concatenates the results.
*
diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala
index 17128b6096..8178d1d5d0 100644
--- a/src/library/scala/Predef.scala
+++ b/src/library/scala/Predef.scala
@@ -61,6 +61,8 @@ object Predef {
type Function[-a,+b] = Function1[a,b]
+ val Map = collection.mutable.Map
+ val Set = collection.mutable.Set
// errors and asserts -------------------------------------------------
diff --git a/src/library/scala/Seq.scala b/src/library/scala/Seq.scala
index da45be6c9c..2b20b978cb 100644
--- a/src/library/scala/Seq.scala
+++ b/src/library/scala/Seq.scala
@@ -78,14 +78,19 @@ trait Seq[+A] extends AnyRef with PartialFunction[Int, A] with Iterable[A] {
/** Appends two iterable objects
*
* @return the new iterable object
+ * @deprecated use <code>++</code> instead
*/
- override def concat [B >: A](that: Iterable[B]): Seq[B] = {
+ [deprecated] override def concat [B >: A](that: Iterable[B]): Seq[B] = {
val buf = new ArrayBuffer[B]
this copyToBuffer buf
that copyToBuffer buf
buf
}
+ /** Appends two iterable objects
+ *
+ * @return the new iterable object
+ */
override def ++ [B >: A](that: Iterable[B]): Seq[B] = {
val buf = new ArrayBuffer[B]
this copyToBuffer buf
diff --git a/src/library/scala/collection/Map.scala b/src/library/scala/collection/Map.scala
index cf23b8cbdf..feb9b2caf0 100644
--- a/src/library/scala/collection/Map.scala
+++ b/src/library/scala/collection/Map.scala
@@ -11,6 +11,8 @@
package scala.collection
+import Predef._
+
//import Predef.NoSuchElementException
diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala
index 837d5e36a4..782d471aa4 100644
--- a/src/library/scala/collection/immutable/ListMap.scala
+++ b/src/library/scala/collection/immutable/ListMap.scala
@@ -24,7 +24,7 @@ object ListMap {
/** The canonical factory for this type
*/
- //def apply[A, B](elems: Pair[A, B]*) = empty[A, B] ++ elems
+ def apply[A, B](elems: Pair[A, B]*) = empty[A, B] ++ elems
}
/** This class implements immutable maps using a list-based data
diff --git a/src/library/scala/collection/immutable/ListSet.scala b/src/library/scala/collection/immutable/ListSet.scala
index 22c2ffa8c9..60a8a17573 100644
--- a/src/library/scala/collection/immutable/ListSet.scala
+++ b/src/library/scala/collection/immutable/ListSet.scala
@@ -27,7 +27,7 @@ object ListSet {
/** The canonical factory for this type
*/
-// def apply[A, B](elems: A*) = empty[A] ++ elems
+ def apply[A, B](elems: A*) = empty[A] ++ elems
}
diff --git a/src/library/scala/collection/immutable/Map.scala b/src/library/scala/collection/immutable/Map.scala
index 64e9e3e04f..8c9b3b75b8 100644
--- a/src/library/scala/collection/immutable/Map.scala
+++ b/src/library/scala/collection/immutable/Map.scala
@@ -32,8 +32,17 @@ package scala.collection.immutable
* @author Erik Stenman
* @author Martin Odersky
* @version 1.2, 31/06/2006
- * todo: make contravariant in A?
*/
+object Map {
+
+ /** The empty map of this type; this is implemented as a treemap */
+ def empty[A <% Ordered[A], B] = new TreeMap[A, B]
+
+ /** The canonical factory for this type
+ */
+ def apply[A <% Ordered[A], B](elems: Pair[A, B]*) = empty[A, B] ++ elems
+}
+
trait Map[A, +B] extends collection.Map[A, B] {
/** This method returns a new map instance of the same class
diff --git a/src/library/scala/collection/immutable/Set.scala b/src/library/scala/collection/immutable/Set.scala
index 81ff1b4718..eadc656470 100644
--- a/src/library/scala/collection/immutable/Set.scala
+++ b/src/library/scala/collection/immutable/Set.scala
@@ -24,6 +24,16 @@ package scala.collection.immutable
* @author Matthias Zenger
* @version 1.1, 03/05/2004
*/
+object Set {
+ /** The empty set of this type
+ */
+ def empty[A <% Ordered[A]] = new TreeSet[A]
+
+ /** The canonical factory for this type
+ */
+ def apply[A <% Ordered[A]](elems: A*) = empty[A] ++ elems
+}
+
trait Set[A] extends AnyRef with collection.Set[A] {
/** @return an empty set of arbitrary element type
diff --git a/src/library/scala/collection/immutable/TreeMap.scala b/src/library/scala/collection/immutable/TreeMap.scala
index 5386575f9c..9e43f092df 100644
--- a/src/library/scala/collection/immutable/TreeMap.scala
+++ b/src/library/scala/collection/immutable/TreeMap.scala
@@ -25,7 +25,7 @@ object TreeMap {
/** The canonical factory for this type
*/
-// def apply[A, B](elems: Pair[A, B]*) = empty[A, B] ++ elems
+ def apply[A <% Ordered[A], B](elems: Pair[A, B]*) = empty[A, B] ++ elems
}
/** This class implements immutable maps using a tree.
diff --git a/src/library/scala/collection/immutable/TreeSet.scala b/src/library/scala/collection/immutable/TreeSet.scala
index 3402adca79..e17763c663 100644
--- a/src/library/scala/collection/immutable/TreeSet.scala
+++ b/src/library/scala/collection/immutable/TreeSet.scala
@@ -21,6 +21,10 @@ object TreeSet {
/** The empty set of this type
*/
def empty[A <% Ordered[A]] = new TreeSet[A]
+
+ /** The canonical factory for this type
+ */
+ def apply[A <% Ordered[A]](elems: A*) = empty[A] ++ elems
}
/** This class implements immutable sets using a tree.
diff --git a/src/library/scala/collection/immutable/UnbalancedTreeMap.scala b/src/library/scala/collection/immutable/UnbalancedTreeMap.scala
index c96d1b7f66..965c4729c6 100755
--- a/src/library/scala/collection/immutable/UnbalancedTreeMap.scala
+++ b/src/library/scala/collection/immutable/UnbalancedTreeMap.scala
@@ -14,7 +14,13 @@ package scala.collection.immutable
object UnbalancedTreeMap {
- def Empty[A <% Ordered[A], B] = new UnbalancedTreeMap[A, B]
+
+ /** The empty map of this type */
+ def empty[A <% Ordered[A], B] = new UnbalancedTreeMap[A, B]
+
+ /** The canonical factory for this type
+ */
+ def apply[A<% Ordered[A], B](elems: Pair[A, B]*) = empty[A, B] ++ elems
}
/** This class implements immutable maps using a tree.
@@ -28,7 +34,7 @@ class UnbalancedTreeMap[A <% Ordered[A], +B] extends Map[A, B] {
/** A factory to create empty maps of the same type of keys.
*/
- def empty[C] = UnbalancedTreeMap.Empty[A, C]
+ def empty[C] = UnbalancedTreeMap.empty[A, C]
def size: Int = 0
diff --git a/src/library/scala/collection/mutable/DefaultMapModel.scala b/src/library/scala/collection/mutable/DefaultMapModel.scala
index c7409774bd..f5f6befcb0 100644
--- a/src/library/scala/collection/mutable/DefaultMapModel.scala
+++ b/src/library/scala/collection/mutable/DefaultMapModel.scala
@@ -11,6 +11,8 @@
package scala.collection.mutable
+import Predef._
+
/** This class is used internally. It implements the mutable <code>Map</code>
* class in terms of three functions: <code>findEntry</code>,
* <code>addEntry</code>, and <code>entries</code>.
diff --git a/src/library/scala/collection/mutable/HashMap.scala b/src/library/scala/collection/mutable/HashMap.scala
index c75b6101f5..d7bd56498f 100644
--- a/src/library/scala/collection/mutable/HashMap.scala
+++ b/src/library/scala/collection/mutable/HashMap.scala
@@ -11,12 +11,24 @@
package scala.collection.mutable
+import Predef._
+
/** This class implements mutable maps using a hashtable.
*
* @author Matthias Zenger
* @author Martin Odersky
* @version 2.0, 31/12/2006
*/
+object HashMap {
+
+ /** The empty map of this type */
+ def empty[A, B] = new HashMap[A, B]
+
+ /** The canonical factory for this type
+ */
+ def apply[A, B](elems: Pair[A, B]*) = empty[A, B] ++ elems
+}
+
[serializable]
class HashMap[A, B] extends Map[A,B] with HashTable[A] with DefaultMapModel[A,B] {
diff --git a/src/library/scala/collection/mutable/HashSet.scala b/src/library/scala/collection/mutable/HashSet.scala
index 7db50fc049..3d53c7e223 100644
--- a/src/library/scala/collection/mutable/HashSet.scala
+++ b/src/library/scala/collection/mutable/HashSet.scala
@@ -14,8 +14,19 @@ package scala.collection.mutable
/** This class implements mutable sets using a hashtable.
*
* @author Matthias Zenger
- * @version 1.0, 08/07/2003
+ * @author Martin Odersky
+ * @version 2.0, 31/12/2006
*/
+object HashSet {
+
+ /** The empty map of this type */
+ def empty[A] = new HashSet[A]
+
+ /** The canonical factory for this type
+ */
+ def apply[A](elems: A*) = empty[A] ++ elems
+}
+
[serializable]
class HashSet[A] extends Set[A] with HashTable[A] {
diff --git a/src/library/scala/collection/mutable/Map.scala b/src/library/scala/collection/mutable/Map.scala
index 75d14e58fd..c94f9a6617 100644
--- a/src/library/scala/collection/mutable/Map.scala
+++ b/src/library/scala/collection/mutable/Map.scala
@@ -11,6 +11,8 @@
package scala.collection.mutable
+import Predef._
+
//import Predef.UnsupportedOperationException
/** This class represents mutable maps. Concrete map implementations
@@ -19,8 +21,20 @@ package scala.collection.mutable
* and <code>-=</code>.
*
* @author Matthias Zenger
- * @version 1.1, 09/05/2004
+ * @author Martin Odersky
+ * @version 2.0, 31/12/2006
*/
+
+object Map {
+
+ /** The empty map of this type; this is implemented as a hashtable */
+ def empty[A, B] = new HashMap[A, B]
+
+ /** The canonical factory for this type
+ */
+ def apply[A, B](elems: Pair[A, B]*) = empty[A, B] ++ elems
+}
+
[cloneable]
trait Map[A, B] extends AnyRef
with collection.Map[A, B]
diff --git a/src/library/scala/collection/mutable/Set.scala b/src/library/scala/collection/mutable/Set.scala
index 26a827dcd9..c05bfebfd6 100644
--- a/src/library/scala/collection/mutable/Set.scala
+++ b/src/library/scala/collection/mutable/Set.scala
@@ -21,6 +21,16 @@ package scala.collection.mutable
* @author Matthias Zenger
* @version 1.1, 09/05/2004
*/
+object Set {
+
+ /** The empty map of this type; this is implemented as a hashtable */
+ def empty[A] = new HashSet[A]
+
+ /** The canonical factory for this type
+ */
+ def apply[A](elems: A*) = empty[A] ++ elems
+}
+
[cloneable]
trait Set[A] extends collection.Set[A] with Scriptable[Message[A]] {
@@ -120,7 +130,7 @@ trait Set[A] extends collection.Set[A] with Scriptable[Message[A]] {
*
* @param elem the element to be removed
*/
- def - (elem: A) { -=(elem); this }
+ def - (elem: A): Set[A] = { -=(elem); this }
/** Remove two or more elements from this set.
* @param elem1 the first element.