diff options
author | Martin Odersky <odersky@gmail.com> | 2011-04-24 20:13:40 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2011-04-24 20:13:40 +0000 |
commit | 290f3711d51da0e013e37ef2703cf976a26747cf (patch) | |
tree | 8097db9aef65c240f618051fef56926928de060a /src/library/scala/collection/SeqLike.scala | |
parent | 60463a8721728545d7d626d96f77e8688084c71f (diff) | |
download | scala-290f3711d51da0e013e37ef2703cf976a26747cf.tar.gz scala-290f3711d51da0e013e37ef2703cf976a26747cf.tar.bz2 scala-290f3711d51da0e013e37ef2703cf976a26747cf.zip |
Added a bunch of bridges to make ameliorate bin...
Added a bunch of bridges to make ameliorate binary compatibility of new
collections. Review by prokopec. Review by extempore.
Diffstat (limited to 'src/library/scala/collection/SeqLike.scala')
-rw-r--r-- | src/library/scala/collection/SeqLike.scala | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index 87649e8b03..0411a2987e 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -14,6 +14,7 @@ import mutable.{ListBuffer, HashMap, ArraySeq} import immutable.{List, Range} import generic._ import parallel.ParSeq +import annotation.bridge /** A template trait for sequences of type `Seq[A]` * $seqInfo @@ -303,6 +304,9 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] !j.hasNext } + @bridge + def startsWith[B](that: Seq[B], offset: Int): Boolean = startsWith(that: GenSeq[B], offset) + def endsWith[B](that: GenSeq[B]): Boolean = { val i = this.iterator.drop(length - that.length) val j = that.iterator @@ -313,6 +317,10 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] !j.hasNext } + @bridge + def endsWith[B](that: Seq[B]): Boolean = endsWith(that: GenSeq[B]) + + /** Finds first index where this $coll contains a given sequence as a slice. * $mayNotTerminateInf * @param that the sequence to test @@ -321,6 +329,9 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] */ def indexOfSlice[B >: A](that: GenSeq[B]): Int = indexOfSlice(that, 0) + @bridge + def indexOfSlice[B >: A](that: Seq[B]): Int = indexOfSlice(that: GenSeq[B]) + /** Finds first index after or at a start index where this $coll contains a given sequence as a slice. * $mayNotTerminateInf * @param that the sequence to test @@ -344,6 +355,9 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] -1 } + @bridge + def indexOfSlice[B >: A](that: Seq[B], from: Int): Int = indexOfSlice(that: GenSeq[B], from) + /** Finds last index where this $coll contains a given sequence as a slice. * $willNotTerminateInf * @param that the sequence to test @@ -352,6 +366,9 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] */ def lastIndexOfSlice[B >: A](that: GenSeq[B]): Int = lastIndexOfSlice(that, length) + @bridge + def lastIndexOfSlice[B >: A](that: Seq[B]): Int = lastIndexOfSlice(that: GenSeq[B]) + /** Finds last index before or at a given end index where this $coll contains a given sequence as a slice. * @param that the sequence to test * @param end the end index @@ -361,6 +378,9 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] def lastIndexOfSlice[B >: A](that: GenSeq[B], end: Int): Int = SeqLike.lastIndexOf(thisCollection, 0, length, that.seq, 0, that.length, end) + @bridge + def lastIndexOfSlice[B >: A](that: Seq[B], end: Int): Int = lastIndexOfSlice(that: GenSeq[B], end) + /** Tests whether this $coll contains a given sequence as a slice. * $mayNotTerminateInf * @param that the sequence to test @@ -369,6 +389,9 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] */ def containsSlice[B](that: GenSeq[B]): Boolean = indexOfSlice(that) != -1 + @bridge + def containsSlice[B](that: Seq[B]): Boolean = containsSlice(that: GenSeq[B]) + /** Tests whether this $coll contains a given value as an element. * $mayNotTerminateInf * @@ -429,6 +452,9 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] b.result } + @bridge + def diff[B >: A](that: Seq[B]): Repr = diff(that: GenSeq[B]) + /** Computes the multiset intersection between this $coll and another sequence. * $mayNotTerminateInf * @@ -459,6 +485,9 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] b.result } + @bridge + def intersect[B >: A](that: Seq[B]): Repr = intersect(that: GenSeq[B]) + private def occCounts[B](sq: Seq[B]): mutable.Map[B, Int] = { val occ = new mutable.HashMap[B, Int] { override def default(k: B) = 0 } for (y <- sq.seq) occ(y) += 1 @@ -491,6 +520,10 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] b.result } + @bridge + def patch[B >: A, That](from: Int, patch: Seq[B], replaced: Int)(implicit bf: CanBuildFrom[Repr, B, That]): That = + this.patch(from, patch: GenSeq[B], replaced)(bf) + def updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) val (prefix, rest) = this.splitAt(index) @@ -536,6 +569,10 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] !i.hasNext && !j.hasNext } + @bridge + def corresponds[B](that: Seq[B])(p: (A,B) => Boolean): Boolean = + corresponds(that: GenSeq[B])(p) + /** Sorts this $coll according to a comparison function. * $willNotTerminateInf * |