scala.collection.generic

trait VectorTemplate

[source: scala/collection/generic/VectorTemplate.scala]

trait VectorTemplate[+A, +This <: VectorTemplate[A, This] with Vector[A]]
extends SequenceTemplate[A, This]
Sequences that support O(1) element access and O(1) length computation. This class does not add any methods to Sequence but overrides several methods with optimized implementations.
Author
Sean McDirmid
Martin Odersky
Version
2.8
Direct Known Subclasses:
Array, Vector, MutableVectorTemplate, VectorViewTemplate, Vector, ArrayBuffer, ResizableArray, RichString

Method Summary
override def copyToArray [B >: A](xs : Array[B], start : Int, len : Int) : Unit
Fills the given array xs with at most `len` elements of this traversable starting at position `start`. Copying will stop once either the end of the current traversable is reached or `len` elements have been copied or the end of the array is reached.
override def drop (n : Int) : This
Returns this traversable without its n first elements If this traversable has less than n elements, the empty traversable is returned.
override def dropRight (n : Int) : This
Returns the iterable wihtout its rightmost n elements.
override def dropWhile (p : (A) => Boolean) : This
Returns the longest suffix of this traversable whose first element does not satisfy the predicate p.
override def endsWith [B](that : Sequence[B]) : Boolean
override def equals (that : Any) : Boolean
This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.
override def exists (p : (A) => Boolean) : Boolean
Return true iff there is an element in this traversable for which the given predicate `p` yields true.
override def find (p : (A) => Boolean) : Option[A]
Find and return the first element of the traversable object satisfying a predicate, if any.
override def foldLeft [B](z : B)(op : (B, A) => B) : B
Combines the elements of this traversable object together using the binary function f, from left to right, and starting with the value z.
override def foldRight [B](z : B)(op : (A, B) => B) : B
Combines the elements of this iterable together using the binary function f, from right to left, and starting with the value z.
override def forall (p : (A) => Boolean) : Boolean
Return true iff the given predicate `p` yields true for all elements of this traversable.
override def foreach [U](f : (A) => U) : Unit
Apply a function f to all elements of this traversable object.
override def head : A
The first element of this iterable.
override def indexWhere (p : (A) => Boolean, from : Int) : Int
Returns index of the first element starting from a start index satisying a predicate, or -1, if none exists.
override def init : This
An traversable consisting of all elements of this traversable except the last one.
override def isEmpty : Boolean
Does this iterable contain no elements?
override def iterator : Iterator[A]
Creates a new iterator over all elements contained in this iterable object.
override def last : A
The last element of this traversable.
override def lastIndexWhere (p : (A) => Boolean, end : Int) : Int
Returns index of the last element not exceeding a given end index and satisying a predicate, or -1 if none exists.
override def lengthCompare (len : Int) : Int
Result of comparing length with operand len. returns x where x < 0 iff this.length < len x == 0 iff this.length == len x > 0 iff this.length > len. The method as implemented here does not call length directly; its running time is O(length min len) instead of O(length). The method should be overwritten if computing length is cheap.
override def reduceLeft [B >: A](op : (B, A) => B) : B
Combines the elements of this traversable object together using the binary operator op, from left to right
override def reduceRight [B >: A](op : (A, B) => B) : B
Combines the elements of this iterable object together using the binary operator op, from right to left
override def reverse : This
A sequence of type C consisting of all elements of this sequence in reverse order.
override def reverseIterator : Iterator[A]
The elements of this sequence in reversed order
override def sameElements [B >: A](that : Iterable[B]) : Boolean
Checks if the other iterable object contains the same elements as this one.
override def segmentLength (p : (A) => Boolean, from : Int) : Int
Returns length of longest segment starting from a start index `from` such that every element of the segment satisfies predicate `p`.
override def slice (from : Int, until : Int) : This
A sub-traversable starting at index `from` and extending up to (but not including) index `until`.
override def span (p : (A) => Boolean) : (This, This)
Returns a pair consisting of the longest prefix of the traversable whose elements all satisfy the given predicate, and the rest of the traversable.
override def splitAt (n : Int) : (This, This)
Split the traversable at a given point and return the two parts thus created.
override def startsWith [B](that : Sequence[B], offset : Int) : Boolean
Checks whether the argument sequence is contained at the specified index within the receiver object. If the both the receiver object, this and the argument, that are infinite sequences this method may not terminate.
override def tail : This
An traversable consisting of all elements of this traversable except the first one.
override def take (n : Int) : This
Return an traversable consisting only of the first n elements of this traversable, or else the whole traversable, if it has less than n elements.
override def takeRight (n : Int) : This
Returns the rightmost n elements from this iterable.
override def takeWhile (p : (A) => Boolean) : This
Returns the longest prefix of this traversable whose elements satisfy the predicate p.
override def view : VectorView[A, This]
Creates a view of this iterable @see IterableView
override def view (from : Int, until : Int) : VectorView[A, This]
A sub-iterable view starting at index `from` and extending up to (but not including) index `until`.
override def zip [A1 >: A, B, That](that : Sequence[B])(implicit bf : BuilderFactory[(A1, B), That, This]) : That
Returns an iterable formed from this iterable and another iterable by combining corresponding elements in pairs. If one of the two iterables is longer than the other, its remaining elements are ignored.
override def zipWithIndex [A1 >: A, That](implicit bf : BuilderFactory[(A1, Int), That, This]) : That
Zips this iterable with its indices (startiong from 0).
Methods inherited from SequenceTemplate
length (abstract), apply (abstract), size, isDefinedAt, zipAll, prefixLength, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, reversedElements, startsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, patch, padTo, toSequence, indices, toString, sortWith, findLastIndexOf, slice, equalsWith, containsSlice, projection
Methods inherited from IterableTemplate
elements, toIterable, toStream, first, firstOption, toSeq
Methods inherited from TraversableTemplate
newBuilder (abstract), thisCollection, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterMap, filterNot, remove, partition, groupBy, count, /:, :\, reduceLeftOption, reduceRightOption, headOption, lastOption, copyToBuffer, copyToArray, toArray, toList, toSet, mkString, mkString, mkString, addString, addString, addString, stringPrefix
Methods inherited from AnyRef
getClass, hashCode, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Class Summary
protected class Elements (start : Int, end : Int) extends BufferedIterator[A]
The iterator returned by the iterator method
Method Details
override def iterator : Iterator[A]
Creates a new iterator over all elements contained in this iterable object.
Returns
the new iterator

override def isEmpty : Boolean
Does this iterable contain no elements?

override def foreach[U](f : (A) => U) : Unit
Apply a function f to all elements of this traversable object.
Parameters
f - A function that is applied for its side-effect to every element. The result (of arbitrary type U) of function `f` is discarded.
Notes
This method underlies the implementation of most other bulk operations. Implementing `foreach` with `iterator` is often suboptimal. So `foreach` should be overridden in concrete collection classes if a more efficient implementation is available.

override def forall(p : (A) => Boolean) : Boolean
Return true iff the given predicate `p` yields true for all elements of this traversable.
Notes
May not terminate for infinite-sized collections.
Parameters
p - the predicate

override def exists(p : (A) => Boolean) : Boolean
Return true iff there is an element in this traversable for which the given predicate `p` yields true.
Notes
May not terminate for infinite-sized collections.
Parameters
p - the predicate

override def find(p : (A) => Boolean) : Option[A]
Find and return the first element of the traversable object satisfying a predicate, if any.
Notes
may not terminate for infinite-sized collections.
Might return different results for different runs, unless this traversable is ordered.
Parameters
p - the predicate
Returns
an option containing the first element in the traversable object satisfying p, or None if none exists.

override def foldLeft[B](z : B)(op : (B, A) => B) : B
Combines the elements of this traversable object together using the binary function f, from left to right, and starting with the value z.
Notes
Will not terminate for infinite-sized collections.
Might return different results for different runs, unless this traversable is ordered, or the operator is associative and commutative.
Returns
f(... (f(f(z, a0), a1) ...), an) if the traversable is [a0, a1, ..., an].

override def foldRight[B](z : B)(op : (A, B) => B) : B
Combines the elements of this iterable together using the binary function f, from right to left, and starting with the value z.
Notes
Will not terminate for infinite-sized collections.
Might return different results for different runs, unless this iterable is ordered, or the operator is associative and commutative.
Returns
f(a0, f(a1, f(..., f(an, z)...))) if the iterable is [a0, a1, ..., an].

override def reduceLeft[B >: A](op : (B, A) => B) : B
Combines the elements of this traversable object together using the binary operator op, from left to right
Notes
Will not terminate for infinite-sized collections.
Might return different results for different runs, unless this traversable is ordered, or the operator is associative and commutative.
Parameters
op - The operator to apply
Returns
op(... op(a0,a1), ..., an) if the traversable object has elements a0, a1, ..., an.
Throws
Predef.UnsupportedOperationException - if the traversable object is empty.

override def reduceRight[B >: A](op : (A, B) => B) : B
Combines the elements of this iterable object together using the binary operator op, from right to left
Notes
Will not terminate for infinite-sized collections.
Might return different results for different runs, unless this iterable is ordered, or the operator is associative and commutative.
Parameters
op - The operator to apply
Returns
a0 op (... op (an-1 op an)...) if the iterable object has elements a0, a1, ..., an.
Throws
Predef.UnsupportedOperationException - if the iterator is empty.

override def zip[A1 >: A, B, That](that : Sequence[B])(implicit bf : BuilderFactory[(A1, B), That, This]) : That
Returns an iterable formed from this iterable and another iterable by combining corresponding elements in pairs. If one of the two iterables is longer than the other, its remaining elements are ignored.
Parameters
that - The iterable providing the second half of each result pair
Overrides
SequenceTemplate.zip

override def zipWithIndex[A1 >: A, That](implicit bf : BuilderFactory[(A1, Int), That, This]) : That
Zips this iterable with its indices (startiong from 0).
Overrides
SequenceTemplate.zipWithIndex

override def slice(from : Int, until : Int) : This
A sub-traversable starting at index `from` and extending up to (but not including) index `until`.
Notes
c.slice(from, to) is equivalent to (but possibly more efficient than) c.drop(from).take(to - from)
Might return different results for different runs, unless this traversable is ordered
Parameters
from - The index of the first element of the returned subsequence
until - The index of the element following the returned subsequence

override def head : A
The first element of this iterable.
Notes
Might return different results for different runs, unless this iterable is ordered
Throws
Predef.NoSuchElementException - if the iterable is empty.

override def tail : This
An traversable consisting of all elements of this traversable except the first one.
Notes
Might return different results for different runs, unless this traversable is ordered

override def last : A
The last element of this traversable.
Throws
Predef.NoSuchElementException - if the traversable is empty.
Notes
Might return different results for different runs, unless this traversable is ordered

override def init : This
An traversable consisting of all elements of this traversable except the last one.
Throws
Predef.UnsupportedOperationException - if the stream is empty.
Notes
Might return different results for different runs, unless this traversable is ordered

override def take(n : Int) : This
Return an traversable consisting only of the first n elements of this traversable, or else the whole traversable, if it has less than n elements.
Parameters
n - the number of elements to take
Notes
Might return different results for different runs, unless this traversable is ordered

override def drop(n : Int) : This
Returns this traversable without its n first elements If this traversable has less than n elements, the empty traversable is returned.
Parameters
n - the number of elements to drop
Returns
the new traversable
Notes
Might return different results for different runs, unless this traversable is ordered

override def takeRight(n : Int) : This
Returns the rightmost n elements from this iterable.
Parameters
n - the number of elements to take
Notes
Might return different results for different runs, unless this iterable is ordered

override def dropRight(n : Int) : This
Returns the iterable wihtout its rightmost n elements.
Parameters
n - the number of elements to take
Notes
Might return different results for different runs, unless this iterable is ordered

override def splitAt(n : Int) : (This, This)
Split the traversable at a given point and return the two parts thus created.
Parameters
n - the position at which to split
Returns
a pair of traversables composed of the first n elements, and the other elements.
Notes
Might return different results for different runs, unless this traversable is ordered

override def takeWhile(p : (A) => Boolean) : This
Returns the longest prefix of this traversable whose elements satisfy the predicate p.
Parameters
p - the test predicate.
Notes
Might return different results for different runs, unless this traversable is ordered

override def dropWhile(p : (A) => Boolean) : This
Returns the longest suffix of this traversable whose first element does not satisfy the predicate p.
Parameters
p - the test predicate.
Notes
Might return different results for different runs, unless this traversable is ordered

override def span(p : (A) => Boolean) : (This, This)
Returns a pair consisting of the longest prefix of the traversable whose elements all satisfy the given predicate, and the rest of the traversable.
Parameters
p - the test predicate
Returns
a pair consisting of the longest prefix of the traversable whose elements all satisfy p, and the rest of the traversable.
Notes
Might return different results for different runs, unless this traversable is ordered

override def sameElements[B >: A](that : Iterable[B]) : Boolean
Checks if the other iterable object contains the same elements as this one.
Notes
will not terminate for infinite-sized iterables.
Might return different results for different runs, unless this iterable is ordered
Parameters
that - the other iterable
Returns
true, iff both iterables contain the same elements.

override def copyToArray[B >: A](xs : Array[B], start : Int, len : Int) : Unit
Fills the given array xs with at most `len` elements of this traversable starting at position `start`. Copying will stop once either the end of the current traversable is reached or `len` elements have been copied or the end of the array is reached.
Notes
Will not terminate for infinite-sized collections.
Parameters
xs - the array to fill.
start - starting index.
len - number of elements to copy

override def lengthCompare(len : Int) : Int
Result of comparing length with operand len. returns x where x < 0 iff this.length < len x == 0 iff this.length == len x > 0 iff this.length > len. The method as implemented here does not call length directly; its running time is O(length min len) instead of O(length). The method should be overwritten if computing length is cheap.
Overrides
SequenceTemplate.lengthCompare

override def segmentLength(p : (A) => Boolean, from : Int) : Int
Returns length of longest segment starting from a start index `from` such that every element of the segment satisfies predicate `p`.
Notes
may not terminate for infinite-sized collections.
Parameters
p - the predicate
from - the start index
Overrides
SequenceTemplate.segmentLength

override def indexWhere(p : (A) => Boolean, from : Int) : Int
Returns index of the first element starting from a start index satisying a predicate, or -1, if none exists.
Notes
may not terminate for infinite-sized collections.
Parameters
p - the predicate
from - the start index
Overrides
SequenceTemplate.indexWhere

override def lastIndexWhere(p : (A) => Boolean, end : Int) : Int
Returns index of the last element not exceeding a given end index and satisying a predicate, or -1 if none exists.
Parameters
end - the end index
p - the predicate
Overrides
SequenceTemplate.lastIndexWhere

override def reverse : This
A sequence of type C consisting of all elements of this sequence in reverse order.
Notes
the operation is implemented by building a new sequence from this(length - 1), ..., this(0) If random access is inefficient for the given sequence implementation, this operation should be overridden.
Overrides
SequenceTemplate.reverse

override def reverseIterator : Iterator[A]
The elements of this sequence in reversed order
Overrides
SequenceTemplate.reverseIterator

override def startsWith[B](that : Sequence[B], offset : Int) : Boolean
Checks whether the argument sequence is contained at the specified index within the receiver object. If the both the receiver object, this and the argument, that are infinite sequences this method may not terminate.
Returns
true if that is contained in this, at the specified index, otherwise false
See Also
String.startsWith
Overrides
SequenceTemplate.startsWith

override def endsWith[B](that : Sequence[B]) : Boolean
Returns
true if this sequence end with that sequence
See Also
String.endsWith
Overrides
SequenceTemplate.endsWith

override def equals(that : Any) : Boolean
This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

The default implementations of this method is an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type AnyRef if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is often necessary to override hashCode to ensure that objects that are "equal" (o1.equals(o2) returns true) hash to the same Int (o1.hashCode.equals(o2.hashCode)).

Parameters
arg0 - the object to compare against this object for equality.
Returns
true if the receiver object is equivalent to the argument; false otherwise.

Overrides
SequenceTemplate.equals

override def view : VectorView[A, This]
Creates a view of this iterable @see IterableView
Overrides
SequenceTemplate.view

override def view(from : Int, until : Int) : VectorView[A, This]
A sub-iterable view starting at index `from` and extending up to (but not including) index `until`.
Parameters
from - The index of the first element of the slice
until - The index of the element following the slice
Notes
The difference between `view` and `slice` is that `view` produces a view of the current iterable, whereas `slice` produces a new iterable.
Might return different results for different runs, unless this iterable is ordered
view(from, to) is equivalent to view.slice(from, to)
Overrides
SequenceTemplate.view