summaryrefslogblamecommitdiff
path: root/src/library/scala/collection/immutable/Vector.scala
blob: 41b4be580ab4fc10087e635552c2d1d03a6554c7 (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                                          

                                           



                                                              



                                                       
                                                    


                                               
                                                                                                          


                                        
                                                                                                   
                                                                                                
 
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2009, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */
package scala.collection.immutable

import scala.collection.generic._
import scala.collection.mutable.ArrayBuffer

/** A subtrait of collection.Vector which represents sequences
 *  that cannot be mutated.
 */
trait Vector[+A] extends Sequence[A]
                    with collection.Vector[A]
                    with TraversableClass[A, Vector]
                    with VectorTemplate[A, Vector[A]] {
  override def companion: Companion[Vector] = Vector
}

object Vector extends SequenceFactory[Vector] {
  class Impl[A](buf: ArrayBuffer[A]) extends Vector[A] { // todo: insert better vector implementation here
    def length = buf.length
    def apply(idx: Int) = buf.apply(idx)
  }
  implicit def builderFactory[A]: BuilderFactory[A, Vector[A], Coll] = new VirtualBuilderFactory[A]
  def newBuilder[A]: Builder[A, Vector[A]] = new ArrayBuffer[A] mapResult (buf => new Impl(buf))
}