diff options
author | Martin Odersky <odersky@gmail.com> | 2009-02-05 19:25:43 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-02-05 19:25:43 +0000 |
commit | 0ecacced0347e4e3b83989a274b9de53868a3a57 (patch) | |
tree | cf5bb351b3acef82ad88862bee320b9c6e32a4c3 /src/library/scalax/collection/generic | |
parent | 48355ee28a930f19000901d761f24ca44b324c1f (diff) | |
download | scala-0ecacced0347e4e3b83989a274b9de53868a3a57.tar.gz scala-0ecacced0347e4e3b83989a274b9de53868a3a57.tar.bz2 scala-0ecacced0347e4e3b83989a274b9de53868a3a57.zip |
added support for Strings, arrays, sets.
Diffstat (limited to 'src/library/scalax/collection/generic')
15 files changed, 416 insertions, 53 deletions
diff --git a/src/library/scalax/collection/generic/covariant/IterableView.scala b/src/library/scalax/collection/generic/Cloneable.scala index 728b065d55..455c88e47b 100755..100644 --- a/src/library/scalax/collection/generic/covariant/IterableView.scala +++ b/src/library/scalax/collection/generic/Cloneable.scala @@ -6,16 +6,13 @@ ** |/ ** \* */ -// $Id: Iterable.scala 15188 2008-05-24 15:01:02Z stepancheg $ +// $Id: CloneableCollection.scala 16893 2009-01-13 13:09:22Z cunei $ -package scalax.collection.generic.covariant -import annotation.unchecked.uncheckedVariance +package scala.collection.generic -/** A non-strict projection of an iterable. - * @author Sean McDirmid - * @author Martin Odersky - * @note this should really be a virtual class of SequenceFactory +/** A trait for cloneable collections. */ -trait IterableView[+UC[+B] <: Iterable[B], +A] - extends generic.IterableView[UC, A @uncheckedVariance] +trait Cloneable[A <: AnyRef] extends java.lang.Cloneable { + override def clone(): A = super.clone().asInstanceOf[A] +} diff --git a/src/library/scalax/collection/generic/IterableFactory.scala b/src/library/scalax/collection/generic/IterableFactory.scala index 1362e97079..9570970abe 100755 --- a/src/library/scalax/collection/generic/IterableFactory.scala +++ b/src/library/scalax/collection/generic/IterableFactory.scala @@ -26,7 +26,7 @@ trait IterableFactory[CC[A] <: Iterable[A]] { * @param n The number of elements returned * @param elem The element returned each time */ - def fill[A](n: Int, elem: => A): CC[A] = { + def fill[A](n: Int)(elem: => A): CC[A] = { val b = newBuilder[A] var i = 0 while (i < n) { @@ -36,11 +36,17 @@ trait IterableFactory[CC[A] <: Iterable[A]] { b.result } - def fill[A](n1: Int, n2: Int, elem: => A): CC[CC[A]] = - tabulate(n1)(_ => fill(n2, elem)) + def fill[A](n1: Int, n2: Int)(elem: => A): CC[CC[A]] = + tabulate(n1)(_ => fill(n2)(elem)) - def fill[A](n1: Int, n2: Int, n3: Int, elem: => A): CC[CC[CC[A]]] = - tabulate(n1)(_ => fill(n2, n3, elem)) + def fill[A](n1: Int, n2: Int, n3: Int)(elem: => A): CC[CC[CC[A]]] = + tabulate(n1)(_ => fill(n2, n3)(elem)) + + def fill[A](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => A): CC[CC[CC[CC[A]]]] = + tabulate(n1)(_ => fill(n2, n3, n4)(elem)) + + def fill[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => A): CC[CC[CC[CC[CC[A]]]]] = + tabulate(n1)(_ => fill(n2, n3, n4, n5)(elem)) def tabulate[A](n: Int)(f: Int => A): CC[A] = { val b = newBuilder[A] @@ -53,11 +59,16 @@ trait IterableFactory[CC[A] <: Iterable[A]] { } def tabulate[A](n1: Int, n2: Int)(f: (Int, Int) => A): CC[CC[A]] = - tabulate(n1)(i1 => tabulate(n2)(i2 => f(i1, i2))) + tabulate(n1)(i1 => tabulate(n2)(f(i1, _))) def tabulate[A](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => A): CC[CC[CC[A]]] = - tabulate(n1)(i1 => tabulate(n2)(i2 => tabulate(n3)(i3 => f(i1, i2, i3)))) -// todo: go up to 5(?) + tabulate(n1)(i1 => tabulate(n2, n3)(f(i1, _, _))) + + def tabulate[A](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => A): CC[CC[CC[CC[A]]]] = + tabulate(n1)(i1 => tabulate(n2, n3, n4)(f(i1, _, _, _))) + + def tabulate[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) => A): CC[CC[CC[CC[CC[A]]]]] = + tabulate(n1)(i1 => tabulate(n2, n3, n4, n5)(f(i1, _, _, _, _))) /** Create a sequence of increasing integers in a range. * diff --git a/src/library/scalax/collection/generic/IterableTemplate.scala b/src/library/scalax/collection/generic/IterableTemplate.scala index c2f1fadd9c..adbf5d2de7 100755 --- a/src/library/scalax/collection/generic/IterableTemplate.scala +++ b/src/library/scalax/collection/generic/IterableTemplate.scala @@ -56,6 +56,11 @@ trait IterableTemplate[+CC[/*+*/B] <: IterableTemplate[CC, B] with Iterable[B], */ def newBuilder[B]: Builder[CC, B] + /** Create a new builder for this IterableType + * with a hint what that its size should be size `sizeHint` + */ + def newBuilder[B](sizeHint: Int): Builder[CC, B] = newBuilder[B] + /** Is this collection empty? */ def isEmpty: Boolean = !elements.hasNext @@ -542,7 +547,6 @@ b * @param thatElem element <code>thatElem</code> is used to fill up the string } - /** Creates a view of this iterable @see IterableView */ def view: IterableView[CC, A] = new IterableView[CC, A] { // !!! Martin: We should maybe infer the type parameters here? diff --git a/src/library/scalax/collection/generic/SequenceTemplate.scala b/src/library/scalax/collection/generic/SequenceTemplate.scala index 27bba86ba0..3407f63216 100755 --- a/src/library/scalax/collection/generic/SequenceTemplate.scala +++ b/src/library/scalax/collection/generic/SequenceTemplate.scala @@ -324,6 +324,9 @@ self /*: CC[A]*/ => */ override def toSequence: Sequence[A] = thisCC + /** Force toString from Iterable, not from Function */ + override def toString = super[OrderedIterableTemplate].toString + def indices: Range = 0 until length /** Creates a view of this iterable @see OrderedIterable.View diff --git a/src/library/scalax/collection/generic/SequenceView.scala b/src/library/scalax/collection/generic/SequenceView.scala index 72e863d4f2..aa6f1e50f8 100755 --- a/src/library/scalax/collection/generic/SequenceView.scala +++ b/src/library/scalax/collection/generic/SequenceView.scala @@ -97,7 +97,7 @@ self => if (0 <= from && from < length) new Patched(from, patch, replaced).asCC else throw new IndexOutOfBoundsException(from.toString) override def padTo[B >: A](len: Int, elem: B): SequenceView[UC, B] = - patch(length, fill((len - length) max 0, elem), 0) + patch(length, fill((len - length) max 0)(elem), 0) override def zip[B](that: Iterable[B]): SequenceView[UC, (A, B)] = new Zipped(that.toSequence).asCC override def zipWithIndex: SequenceView[UC, (A, Int)] = diff --git a/src/library/scalax/collection/generic/SetFactory.scala b/src/library/scalax/collection/generic/SetFactory.scala new file mode 100644 index 0000000000..0fbcf68466 --- /dev/null +++ b/src/library/scalax/collection/generic/SetFactory.scala @@ -0,0 +1,9 @@ +package scalax.collection.generic + +trait SetFactory[CC[A] <: SetTemplate[CC, A] with Set[A]] extends IterableFactory[CC] { + + def empty[A]: CC[A] + + def apply[A](elems: A*): CC[A] = empty[A] ++ elems.asInstanceOf[Iterable[A]] // !@! + +} diff --git a/src/library/scalax/collection/generic/SetTemplate.scala b/src/library/scalax/collection/generic/SetTemplate.scala new file mode 100755 index 0000000000..9c3056cc04 --- /dev/null +++ b/src/library/scalax/collection/generic/SetTemplate.scala @@ -0,0 +1,173 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Set.scala 16893 2009-01-13 13:09:22Z cunei $ + + +package scalax.collection.generic + + +/** <p> + * A set is a collection that includes at most one of any object. + * </p> + * <p> + * This trait provides a limited interface, only allowing reading of elements. + * There are two extensions of this trait, in packages + * <code><a href="mutable$content.html" target="contentFrame"> + * scala.collection.mutable</a></code> + * and <code><a href="immutable$content.html" target="contentFrame"> + * scala.collection.immutable</a></code>, which provide functionality for + * adding and removing objects from the set. The trait in the first package is + * for sets that are modified destructively, whereas the trait in + * the second package is for immutable sets which create a new set + * when something is added or removed to them. + * + * @author Matthias Zenger + * @author Martin Odersky + * @version 2.8 + */ +trait SetTemplate[+CC[B] <: SetTemplate[CC, B] with Set[B], A] extends (A => Boolean) with SizedIterable[A] with OrderedIterableTemplate[CC, A] { + + /** Returns the number of elements in this set. + * + * @return number of set elements. + */ + def size: Int + + /** Creates a new set of this kind with given elements */ + def newBuilder[B]: Builder[CC, B] + + /** Checks if this set contains element <code>elem</code>. + * + * @param elem the element to check for membership. + * @return <code>true</code> iff <code>elem</code> is contained in + * this set. + */ + def contains(elem: A): Boolean + + /** Create a new set with an additional element. + */ + def +(elem: A): CC[A] + + /** Remove a single element from a set. + * @param elem the element to be removed + * @return a new set with the element removed. + */ + def -(elem: A): CC[A] + + /** Checks if this set is empty. + * + * @return <code>true</code> iff there is no element in the set. + */ + override def isEmpty: Boolean = size == 0 + + /** This method allows sets to be interpreted as predicates. + * It returns <code>true</code>, iff this set contains element + * <code>elem</code>. + * + * @param elem the element to check for membership. + * @return <code>true</code> iff <code>elem</code> is contained in + * this set. + */ + def apply(elem: A): Boolean = contains(elem) + + /** Add two or more elements to this set. + * @param elem1 the first element. + * @param elem2 the second element. + * @param elems the remaining elements. + * @return a new set with the elements added. + */ + def + (elem1: A, elem2: A, elems: A*): CC[A] = { + thisCC + elem1 + elem2 ++ elems.asInstanceOf[Iterable[A]] + } + + /** Remove two or more elements from this set. + * + * @param elem1 the first element. + * @param elem2 the second element. + * @param elems the remaining elements. + * @return a new set with the elements removed. + */ + def - (elem1: A, elem2: A, elems: A*): CC[A] = + this - elem1 - elem2 -- elems.asInstanceOf[Iterable[A]] + + /** Remove all the elements provided by an iterator + * of the iterable object <code>elems</code> from the set. + * + * @param elems An iterable object containing the elements to remove from the set. + * @return a new set with the elements removed. + */ + def -- (elems: Iterable[A]): CC[A] = this -- elems.elements + + /** Remove all the elements provided by an iterator + * <code>elems</code> from the set. + * + * @param elems An iterator containing the elements to remove from the set. + * @return a new set with the elements removed. + */ + def -- (elems: Iterator[A]): CC[A] = + (thisCC /: elems) (_ - _) + + /** This method computes an intersection with set <code>that</code>. + * It removes all the elements that are not present in <code>that</code>. + * + * @param that the set to intersect with. + */ + def intersect(that: Set[A]): CC[A] = filter(that.contains) + + /** This method is an alias for <code>intersect</code>. + * It computes an intersection with set <code>that</code>. + * It removes all the elements that are not present in <code>that</code>. + * + * @param that the set to intersect with + */ + def ** (that: collection.Set[A]): CC[A] = intersect(that) + + /** Checks if this set is a subset of set <code>that</code>. + * + * @param that another set. + * @return <code>true</code> iff the other set is a superset of + * this set. + * todo: rename to isSubsetOf + */ + def subsetOf(that: Set[A]): Boolean = forall(that.contains) + + /** Compares this set with another object and returns true, iff the + * other object is also a set which contains the same elements as + * this set. + * + * @param that the other object + * @note not necessarily run-time type safe. + * @return <code>true</code> iff this set and the other set + * contain the same elements. + * @deprecated equals is not stable for mutable sets. + * If you wish object identity, use eq or cast this set of AnyRef and then use + * equals. If you wish element comparisons, use `sameElements` instead. + */ + @deprecated override def equals(that: Any): Boolean = that match { + case other: Set[_] => + this.size == other.size && subsetOf(other.asInstanceOf[Set[A]]) + case _ => + false + } + + /* @deprecated hashCode is not stable for mutable sets. + * if you intend to have object identity hashCode and wish the deprecated warning + * to go away, cast this set to AnyRef before calling hashCode. + */ + @deprecated override def hashCode() = + (0 /: this)((hash, e) => hash + e.hashCode()) + + /** Defines the prefix of this object's <code>toString</code> representation. + */ + override def stringPrefix: String = "Set" + + /** Need to override string, so that it's not the Function1's string that gets mixed in. + */ + override def toString = super[OrderedIterableTemplate].toString +} diff --git a/src/library/scalax/collection/generic/VectorTemplate.scala b/src/library/scalax/collection/generic/VectorTemplate.scala index 854f4fb3a2..d97fd03aa4 100644 --- a/src/library/scalax/collection/generic/VectorTemplate.scala +++ b/src/library/scalax/collection/generic/VectorTemplate.scala @@ -89,7 +89,7 @@ self => case that: Vector[_] => var i = 0 val len = this.length min that.length - val b = this.newBuilder[(A, B)] + val b = this.newBuilder[(A, B)](len) while (i < len) { b += ((this(i), that(i).asInstanceOf[B])) i += 1 @@ -102,8 +102,10 @@ self => override def zipAll[B, A1 >: A, B1 >: B](that: Iterable[B], thisElem: A1, thatElem: B1): CC[(A1, B1)] = that match { case that: Vector[_] => var i = 0 - val len = this.length min that.length - val b = this.newBuilder[(A1, B1)] + val thisLen = this.length + val thatLen = that.length + val len = thisLen min thatLen + val b = this.newBuilder[(A1, B1)](thisLen max thatLen) while (i < len) { b += ((this(i), that(i).asInstanceOf[B])) i += 1 @@ -122,9 +124,9 @@ self => } override def zipWithIndex: CC[(A, Int)] = { - val b = newBuilder[(A, Int)] - var i = 0 val len = length + val b = newBuilder[(A, Int)](len) + var i = 0 while (i < len) { b += ((this(i), i)) i += 1 @@ -148,9 +150,9 @@ self => override def head: A = if (isEmpty) throw new NoSuchElementException else this(0) override def slice(from: Int, until: Int): CC[A] = { - val b = newBuilder[A] var i = from max 0 val end = until min length + val b = newBuilder[A](end - i) while (i < end) { b += this(i) i += 1 @@ -199,7 +201,7 @@ self => override def lastIndexOf[B >: A](elem: B, end: Int): Int = lastIndexWhere(elem ==, end) override def reverse: CC[A] = { - val b = newBuilder[A] + val b = newBuilder[A](length) var i = length while (0 < i) { i -= 1 diff --git a/src/library/scalax/collection/generic/covariant/IterableTemplate.scala b/src/library/scalax/collection/generic/covariant/IterableTemplate.scala index ae9cd5e1d9..715f88cd8e 100755 --- a/src/library/scalax/collection/generic/covariant/IterableTemplate.scala +++ b/src/library/scalax/collection/generic/covariant/IterableTemplate.scala @@ -23,7 +23,17 @@ import annotation.unchecked.uncheckedVariance * @version 1.1, 04/02/2004 */ trait IterableTemplate[+CC[+B] <: IterableTemplate[CC, B] with Iterable[B], +A] - extends generic.IterableTemplate[CC, A @uncheckedVariance] { self /*: CC[A]*/ => } + extends generic.IterableTemplate[CC, A @uncheckedVariance] { self /*: CC[A]*/ => + +/* can't have a covariant view here, because mutable.Vector would + override it + override def view: IterableView[CC, A] = new IterableView[CC, A] { + val origin = thisCC + val elements: Iterator[A] = self.elements + } +*/ +} + // !!! todo: explain why @uncheckedVariance is justified here. diff --git a/src/library/scalax/collection/generic/covariant/SequenceTemplate.scala b/src/library/scalax/collection/generic/covariant/SequenceTemplate.scala index 2e30e05fbf..1e8a416aec 100755 --- a/src/library/scalax/collection/generic/covariant/SequenceTemplate.scala +++ b/src/library/scalax/collection/generic/covariant/SequenceTemplate.scala @@ -14,4 +14,4 @@ package scalax.collection.generic.covariant import annotation.unchecked.uncheckedVariance trait SequenceTemplate[+CC[+B] <: SequenceTemplate[CC, B] with Sequence[B], +A] - extends generic.SequenceTemplate[CC, A @uncheckedVariance] {self /*: CC[A]*/ => } + extends generic.SequenceTemplate[CC, A @uncheckedVariance] diff --git a/src/library/scalax/collection/generic/covariant/SequenceView.scala b/src/library/scalax/collection/generic/covariant/SequenceView.scala deleted file mode 100755 index eba1795d13..0000000000 --- a/src/library/scalax/collection/generic/covariant/SequenceView.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id: Sequence.scala 16092 2008-09-12 10:37:06Z nielsen $ - - -package scalax.collection.generic.covariant - -import annotation.unchecked.uncheckedVariance - -/** A non-strict projection of an iterable. - * @author Sean McDirmid - * @author Martin Odersky - * @note this should really be a virtual class of SequenceFactory - */ -trait SequenceView[+UC[+B] <: Sequence[B], +A] - extends IterableView[UC, A] with generic.SequenceView[UC, A @uncheckedVariance] diff --git a/src/library/scalax/collection/generic/covartest/SequenceView.scala b/src/library/scalax/collection/generic/covartest/SequenceView.scala index bae43636ae..77b06b0b4f 100755 --- a/src/library/scalax/collection/generic/covartest/SequenceView.scala +++ b/src/library/scalax/collection/generic/covartest/SequenceView.scala @@ -97,7 +97,7 @@ self => if (0 <= from && from < length) new Patched(from, patch, replaced).asCC else throw new IndexOutOfBoundsException(from.toString) override def padTo[B >: A](len: Int, elem: B): SequenceView[UC, B] = - patch(length, fill((len - length) max 0, elem), 0) + patch(length, fill((len - length) max 0)(elem), 0) override def zip[B](that: Iterable[B]): SequenceView[UC, (A, B)] = new Zipped(that.toSequence).asCC override def zipWithIndex: SequenceView[UC, (A, Int)] = diff --git a/src/library/scalax/collection/generic/mutable/Growable.scala b/src/library/scalax/collection/generic/mutable/Growable.scala new file mode 100644 index 0000000000..4d585129ad --- /dev/null +++ b/src/library/scalax/collection/generic/mutable/Growable.scala @@ -0,0 +1,94 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Iterable.scala 15188 2008-05-24 15:01:02Z stepancheg $ + +package scalax.collection.generic.mutable + +/** This class represents collections that can be augmented using a += operator. + * + * @autor Martin Odersky + * @owner Martin Odersky + * @version 2.8 + */ +trait Growable[A] { + + /** Add a single element to this collection. + * + * @param elem the element to add. + */ + def +=(elem: A): Unit + + /** Add a two or more elements to this collection. + * + * @param elem1 the first element to add. + * @param elem2 the second element to add. + * @param elems the remaining elements to add. + */ + def +=(elem1: A, elem2: A, elems: A*) { + this += elem1 + this += elem2 + this ++= elems.asInstanceOf[Iterable[A]] // !@! + } + + /** Adds a number of elements provided by an iterator + * + * @param iter the iterator. + */ + def ++=(iter: collection.Iterator[A]) { iter foreach += } + + /** Adds a number of elements provided by an iterable object + * via its <code>elements</code> method. + * + * @param iter the iterable object. + */ + def ++=(iter: collection.Iterable[A]) { iter foreach += } + + /** Add a single element to this collection and return + * the identity of the collection. + * + * @param elem the element to add. + */ + def +(elem: A): this.type = { this += elem; this } + + /** Add two or more elements to this collection and return + * the identity of the collection. + * + * @param elem1 the first element to add. + * @param elem2 the second element to add. + * @param elems the remaining elements to add. + */ + def +(elem1: A, elem2: A, elems: A*): this.type = + this + elem1 + elem2 ++ elems.asInstanceOf[Iterable[A]] // !@! + + /** Adds a number of elements provided by an iterable object + * via its <code>elements</code> method. The identity of the + * collection is returned. + * + * @param iter the iterable object. + * @return the updated collection. + */ + def ++(iter: Iterable[A]): this.type = { this ++= iter; this } + + /** Adds a number of elements provided by an iterator + * via its <code>elements</code> method. The identity of the + * collection is returned. + * + * @param iter the iterator + * @return the updated collection. + */ + def ++(iter: Iterator[A]): this.type = { this ++= iter; this } + + /** Clears the collection contents. + */ + def clear() +} + + + + diff --git a/src/library/scalax/collection/generic/mutable/Shrinkable.scala b/src/library/scalax/collection/generic/mutable/Shrinkable.scala new file mode 100644 index 0000000000..49e1b57eb6 --- /dev/null +++ b/src/library/scalax/collection/generic/mutable/Shrinkable.scala @@ -0,0 +1,82 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Iterable.scala 15188 2008-05-24 15:01:02Z stepancheg $ + +package scalax.collection.generic.mutable + +/** This class represents collections that can be shrunk using a -= operator. + * + * @autor Martin Odersky + * @owner Martin Odersky + * @version 2.8 + */ +trait Shrinkable[A] { + + /** Remove a single element from this collection. + * + * @param elem the element to append. + */ + def -=(elem: A): Unit + + /** Remove two or more elements from this collection. + * @param elem1 the first element. + * @param elem2 the second element. + * @param elems the remaining elements. + */ + def -= (elem1: A, elem2: A, elems: A*) { + this -= elem1 + this -= elem2 + this --= elems.asInstanceOf[Iterable[A]] // !@! + } + + /** Remove all the elements provided by an iterable + * <code>elems</code> from the collection. + */ + def --=(elems: Iterable[A]) { elems foreach -= } + + /** Remove all the elements provided by an iterator + * <code>elems</code> from the collection. + */ + def --=(elems: Iterator[A]) { elems foreach -= } + /** Remove a single element from the collection. + * @return the collection itself with the element removed. + * + * @param elem the element to be removed + */ + def - (elem: A): this.type = { -=(elem); this } + + /** Remove two or more elements from this collection. + * + * @param elem1 the first element. + * @param elem2 the second element. + * @param elems the remaining elements. + * @return the collection itself with the elements removed. + */ + def - (elem1: A, elem2: A, elems: A*): this.type = { -=(elem1, elem2, elems: _*); this } + + /** Remove all the elements provided by an iterator + * <code>elems</code> from the collection. + * + * @param elems An iterator containing the elements to remove from the collection. + * @return the collection itself with the elements removed. + */ + def -- (elems: Iterable[A]): this.type = { this --= elems; this } + + /** Remove all the elements provided by an iterator + * <code>elems</code> from the collection. + * + * @param elems An iterator containing the elements to remove from the collection. + * @return the collection itself with the elements removed. + */ + def -- (elems: Iterator[A]): this.type = { this --= elems; this } +} + + + + diff --git a/src/library/scalax/collection/generic/mutable/VectorTemplate.scala b/src/library/scalax/collection/generic/mutable/VectorTemplate.scala index b99600948a..4d748a79d1 100644 --- a/src/library/scalax/collection/generic/mutable/VectorTemplate.scala +++ b/src/library/scalax/collection/generic/mutable/VectorTemplate.scala @@ -44,10 +44,10 @@ self => */ override def view(from: Int, until: Int): VectorView[CC, A] = view.slice(from, until) - def readOnly: Sequence[A] = new collection.immutable.Vector[A] { //!!! + def readOnly: collection.Vector[A] = new collection.Vector[A] { //!!! just use a VectorProxy? def length = self.length def apply(idx : Int) = self.apply(idx) - def newBuilder[B]: Builder[CC, B] = self.newBuilder[B] + def newBuilder[B]: Builder[collection.Vector, B] = self.newBuilder[B] //mapResult (_.readOnly) override def foreach(f: A => Unit) = self.foreach(f) override def stringPrefix = self.stringPrefix+"RO" } |