final class Buffer[A] extends Serializable

Buffer is a mutable, indexed sequence of values.

Buffer wraps an underlying array, which provides constant-time lookups, updates, and length checks. Values can be appended to or popped from the end of the buffer in amortized constant time. Other operations, such as insert, prepend, and will be linear.

In cases where the type A is known (or the caller is specialized on A), Buffer[A] will store the values in an unboxed array, and will not box values on access or update. To aid in specialization and to avoid inheriting bogus methods, Buffer intentionally does not implement any of Scala's collection traits.

For interop purposes, the toIterable method wraps a buffer in a collections-compatible Iterable[A]. Buffer's iterator method returns an Iterator[A], and the conversion methods .toArray, toVector, and toList are also available.

To facilitate inlining, Buffer's internals are public. However, you should refrain from accessing or modifying these values unless you know what you are doing.

Furthermore, since Buffer is really only useful in cases where you care about space efficiency and performance, Buffer declines to do error-checking above what is provided by the underlying array, or which is necessary to avoid corruption. This means that if you try to access an element beyond the Buffer's length, you are not guaranteed to get an exception (although you will in many cases). This is by design. However, calls which modify the buffer using an invalid index are guaranteed not to corrupt the buffer.

Finally, there is no attempt made to provide any kind of thread safety or protection against concurrent updates. Modify a Buffer during foreach, map, iterator, etc will produce undefined results.

Self Type
Buffer[A]
Linear Supertypes
Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Buffer
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Buffer(arr: Array[A], n: Int)(implicit ct: ClassTag[A])

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def ++(buf: Buffer[A]): Buffer[A]

    Concatenate two buffers, returning a new buffer.

    Concatenate two buffers, returning a new buffer.

    This method does not modify either input buffer, but allocates and returns a new one.

    This is an O(n+m) operation, where n and m are the lengths of the input buffers.

  4. def ++=(items: Iterable[A]): Unit

    Append the values in elems to the end of the buffer.

    Append the values in elems to the end of the buffer.

    This method is an O(m) operation, where m is the length of items.

  5. def ++=(buf: Buffer[A]): Unit

    Append the values in buf to the end of the buffer.

    Append the values in buf to the end of the buffer.

    This method is an O(m) operation, where m is the length of buf.

  6. def ++=(arr: Array[A]): Unit

    Append the values in arr to the end of the buffer.

    Append the values in arr to the end of the buffer.

    This method is an O(m) operation, where m is the length of arr.

  7. def +=(a: A): Unit

    Append a new value to the end of the buffer.

    Append a new value to the end of the buffer.

    If there is no space left in the underlying array this method will trigger a grow, increasing the underlying storage capacity.

    This is an amortized O(1) operation.

  8. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def append(a: A): Unit

    This method is a synonym for append.

  10. def apply(i: Int): A

    Return the value at element i.

    Return the value at element i.

    As noted above, this method may throw an ArrayIndexOutOfBoundsException if i is too large. However, if i is larger than the buffer's length, but fits in the underlying array, a garbage value will be returned instead. Be careful!

    This is an O(1) operation.

  11. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  12. def clear(): Unit1[A]

    Clears the buffer's internal state.

    Clears the buffer's internal state.

    After calling this method, the buffer's state is identical to that obtained by calling Buffer.empty[A].

    The previous array is not retained, and will become available for garbage collection.

    This is an O(1) operation.

  13. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  14. def compact(): Unit1[A]

    Compacts the buffer's internal array to remove extra free space.

    Compacts the buffer's internal array to remove extra free space.

    This operation should be used it a buffer is not likely to grow again, and the user wants to free any additional memory that may be available.

    In general, a buffer that has only grown will use 1-2x of its apparent size. Buffers that have been reduced in size may be using up to 4x the apparent size.

  15. def concat(buf: Buffer[A]): Buffer[A]

    This is a synonym for ++.

  16. final def copy(): Buffer[A]

    Copy the buffer's contents to a new buffer.

  17. implicit val ct: ClassTag[A]
  18. var elems: Array[A]
  19. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. def equals(that: Any): Boolean

    Check if two Buffers are equal.

    Check if two Buffers are equal.

    Equal means the buffers have the same type (which is checked using the ClassTag instances) and the same contents.

    Comparing Buffers with any of Scala's collection types will return false.

    Definition Classes
    Buffer → AnyRef → Any
  21. def extend(items: Iterable[A]): Unit

    This is a synonym for extend.

  22. def extend(buf: Buffer[A]): Unit

    This is a synonym for extend.

  23. def extend(arr: Array[A]): Unit

    This is a synonym for ++=.

  24. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  25. def foreach(f: Function[A, Unit]): Unit

    Loop over the buffer's contents, appying f to each element.

    Loop over the buffer's contents, appying f to each element.

    This is an O(n) operation, where n is the length of the buffer.

  26. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  27. def hashCode(): Int

    Hash the contents of the buffer to an Int value.

    Hash the contents of the buffer to an Int value.

    Definition Classes
    Buffer → AnyRef → Any
  28. def insert(i: Int, a: A): Unit

    Insert a new value at index i.

    Insert a new value at index i.

    For i values that are negative, or greater than the length of the buffer, an exception will be thrown. If i == buffer.length, the value will be appended to the end. Otherwise, this method will shift the values at i and beyond forward to make room.

    This is an O(n) operation, where n is buffer.length.

  29. def isEmpty: Boolean

    Return true if the Buffer is empty, false otherwise.

    Return true if the Buffer is empty, false otherwise.

    This is an O(1) operation.

  30. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  31. def iterator(): Iterator[A]

    Return an iterator over this buffer's contents.

    Return an iterator over this buffer's contents.

    This method does not do any copying or locking. Thus, if the buffer is modified while the iterator is "live" the results will be undefined and probably bad.

    Use this.copy.iterator to get a "clean" iterator if needed.

    Creating the iterator is an O(1) operation.

  32. var len: Int
  33. def length: Int

    Return the length of this Buffer as an Int.

    Return the length of this Buffer as an Int.

    Since Buffers wrap arrays, their size is limited to what a 32-bit signed integer can represent. In general Buffer should only be used for sequences that are small enough to easily fit into contiguous memory--larger sequences would benefit from block layouts, serialization to/from disk, and other strategies that Buffer does not provide.

    This is an O(1) operation.

  34. def map[B](f: (A) ⇒ B)(implicit arg0: ClassTag[B]): Buffer[B]

    Map this buffer's contents into a new buffer using f.

    Map this buffer's contents into a new buffer using f.

    This is an O(n) operation, where n is the length of the buffer.

  35. def max(implicit o: Order[A]): A

    Find the maximum value in this buffer.

    Find the maximum value in this buffer.

    This method uses an instance of Spire's Order[A] type class to compare the elements, to avoid boxing. If you want to use Scala's Ordering, you can use compatibility code in Spire, or call toIterable.min.

  36. def mean(implicit ev: Field[A]): A

    Find the mean (average) value of this buffer's contents.

  37. def min(implicit o: Order[A]): A

    Find the minimum value in this buffer.

    Find the minimum value in this buffer.

    This method uses an instance of Spire's Order[A] type class to compare the elements, to avoid boxing. If you want to use Scala's Ordering, you can use compatibility code in Spire, or call toIterable.min.

  38. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  39. def nonEmpty: Boolean

    Return true if the Buffer is non-empty, false otherwise.

    Return true if the Buffer is non-empty, false otherwise.

    This is an O(1) operation.

  40. def norm(p: Int)(implicit ev: Field[A], s: Signed[A], nr: NRoot[A]): A

    Find the p-norm of the buffer's contents.

    Find the p-norm of the buffer's contents.

    The p-norm generalizes notion of a length function.

  41. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  42. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  43. def pop(): A

    Remove the last element, returning the value returned.

    Remove the last element, returning the value returned.

    If the buffer is empty, this method throws an exception.

    This method is an O(1) operation.

  44. def prepend(a: A): Unit

    Insert a new value at the beginning of the buffer.

    Insert a new value at the beginning of the buffer.

    This method will shift the contents of the buffer forward to make space for the new value.

    This is an O(n) operation, where n is buffer.length.

  45. def prependAll(buf: Buffer[A]): Unit

    Prepend the values from arr into the beginning of the buffer.

    Prepend the values from arr into the beginning of the buffer.

    Like splice, this method will shift all the buffer's values back to make room.

    This method is an O(m+n) operation, where m is the length of arr, and n is the lenght of the buffer.

  46. def prependAll(arr: Array[A]): Unit

    Prepend the values from arr into the beginning of the buffer.

    Prepend the values from arr into the beginning of the buffer.

    Like splice, this method will shift all the buffer's values back to make room.

    This method is an O(m+n) operation, where m is the length of arr, and n is the lenght of the buffer.

  47. def product(implicit ev: MultiplicativeMonoid[A]): A

    Multiply the buffer contents together, returning their product.

  48. def remove(i: Int): A

    Remove the element at i, returning the value removed.

    Remove the element at i, returning the value removed.

    This method verifies that the index i is valid; if not, it will throw an exception.

    This method is an O(n) operation, where n is buffer.length. Removing the last element of the buffer is O(1) operation, and can also be accomplished with pop.

  49. def reverse(): Buffer[A]

    Return a new buffer with this buffer's elements in reverse order.

    Return a new buffer with this buffer's elements in reverse order.

    This is an O(n) method, where n is buffer.length.

  50. def slice(i: Int, j: Int): Buffer[A]

    Return a new buffer which consists of the elements [i, j).

    Return a new buffer which consists of the elements [i, j).

    The slice is half-open: the resulting buffer will include element i but not element j. In other words, the new buffer will have length (j - i).

    If i and j are not valid indices in the buffer, or if i > j, this method will throw an exception.

    This is an O(j - i) operation.

  51. def sort(implicit o: Order[A]): Unit

    Sort the contents of the buffer.

    Sort the contents of the buffer.

    This method uses an instance of Spire's Order[A] type class to compare the elements, to avoid boxing. If you want to use Scala's Ordering, you can use compatibility code in Spire, or call toIterable.min.

  52. def splice(i: Int, buf: Buffer[A]): Unit

    Splice the values in buf into the buffer at index i.

    Splice the values in buf into the buffer at index i.

    If i is negative or greater than buffer.length, an exception will be thrown. If i is equal to buffer.length, the buffer will be extended with buf. Otherwise, this method will shift the elements at i and beyond forward to make room for buf's elements. Thus, the size of the buffer will increase by buf.length.

    This method is an O(m+n) operation, where m is the length of buf, and n is the length of the buffer.

  53. def splice(i: Int, arr: Array[A]): Unit

    Splice the values in arr into the buffer at index i.

    Splice the values in arr into the buffer at index i.

    If i is negative or greater than buffer.length, an exception will be thrown. If i is equal to buffer.length, the buffer will be extended with arr. Otherwise, this method will shift the elements at i and beyond forward to make room for arr's elements. Thus, the size of the buffer will increase by arr.length.

    This method is an O(m+n) operation, where m is the length of arr, and n is the length of the buffer.

  54. def sum(implicit ev: AdditiveMonoid[A]): A

    Add the buffer contents together, returning their sum.

  55. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  56. def toArray(): Array[A]

    Create an array out of the elements in the buffer.

    Create an array out of the elements in the buffer.

    This is an O(n) operation, where n is the length of the buffer.

  57. def toIterable(): Iterable[A]

    Wrap this buffer in an Iterable[A] instance.

    Wrap this buffer in an Iterable[A] instance.

    This method exists as a cheap way to get compatibility with Scala collections without copying/conversion. Note that since Scala collections are not specialized, using this iterable will box values as they are accessed (although the underlying array will still be unboxed).

    Like iterator, this method directly wraps the buffer. Thus, you should not mutate the buffer while using the resulting iterable, or risk corruption and undefined behavior.

    To get a "safe" value that is compatible with Scala collections, consider using toVector, toList, or copy.toIterable.

    Creating the Iterable[A] instance is an O(1) operation.

  58. def toList(): List[A]

    Create a List[A] from this buffer's elements.

    Create a List[A] from this buffer's elements.

    This is an O(n) operation.

  59. def toString(): String

    Return a string representation of the contents of the buffer.

    Return a string representation of the contents of the buffer.

    Definition Classes
    Buffer → AnyRef → Any
  60. def toVector(): Vector[A]

    Create a Vector[A] from this buffer's elements.

    Create a Vector[A] from this buffer's elements.

    This is an O(n) operation.

  61. def update(i: Int, a: A): Unit

    Update the value of element i.

    Update the value of element i.

    This method has similar caveats to apply. If an illegal i value is used, an ArrayIndexOutOfBoundsException may be thrown. If no exception is thrown, the update will have been ignored. Under no circumstances will an invalid index corrupt the buffer.

    This is an O(1) operation.

  62. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  63. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  64. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped