DeferredArrayBuffer

com.github.arturopala.bufferandslice.DeferredArrayBuffer
See theDeferredArrayBuffer companion object
final class DeferredArrayBuffer[T](initialLength: Int) extends ArrayBufferLike[T]

Growable, mutable array of values with deferred initialization.

Type parameters

T

type of the underlying array items

Value parameters

initialLength

initial length of the buffer

Attributes

Note

This is to avoid ClassTag parameters as much as possible, but comes with a price of a few rough corners. Especially, if your type parameter is non-primitive do not try to call asArray and assign result to variable, as it will raise ClassCastException, instead pass the array as a parameter or call methods on it.

Companion
object
Graph
Supertypes
trait ArrayBufferLike[T]
trait Buffer[T]
trait Int => T
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def apply(index: Int): T

Returns value at the given index.

Returns value at the given index.

Attributes

Throws
IndexOutOfBoundsException

if index out of range [0, length)

RuntimeException

if not yet initialized

Definition Classes
Buffer -> Function1
override def asArray: Array[T]

Returns an array with a copy of an accessible buffer range.

Returns an array with a copy of an accessible buffer range.

Attributes

Throws
RuntimeException

if not yet initialized

Note

this method avoids ClassTag but at the price of: - RuntimeException if non-empty buffer not yet initialized - ClassCastExceptions when assigning returned non-primitive array to a variable. Try using toArray when possible.

Definition Classes
override def asSlice: Slice[T]

Wraps accessible internal state as a Slice without making any copy.

Wraps accessible internal state as a Slice without making any copy.

Attributes

Throws
RuntimeException

if not yet initialized

Definition Classes
override def copy: this.type

Returns copy of this buffer.

Returns copy of this buffer.

Attributes

Definition Classes
override def emptyCopy: this.type

Returns an empty copy of this buffer type.

Returns an empty copy of this buffer type.

Attributes

Definition Classes
override def slice(from: Int, to: Int): Slice[T]

Takes range and returns a Slice.

Takes range and returns a Slice.

Attributes

Throws
RuntimeException

if not yet initialized

Definition Classes
override def toArray[T1 >: T : ClassTag]: Array[T1]

Returns a trimmed copy of an underlying array.

Returns a trimmed copy of an underlying array.

Attributes

Definition Classes

Inherited methods

def andThen[A](g: T => A): Int => A

Attributes

Inherited from:
Function1
final def append(value: T): Buffer.this.type

Appends value at the end of the buffer and advances topIndex.

Appends value at the end of the buffer and advances topIndex.

Attributes

Inherited from:
Buffer
final def appendArray(values: Array[T]): Buffer.this.type

Appends values from the given array at the end of the buffer and advances topIndex.

Appends values from the given array at the end of the buffer and advances topIndex.

Attributes

Inherited from:
Buffer
final def appendFromIterator(numberOfValues: Int, iterator: Iterator[T]): Buffer.this.type

Appends number of values from the given iterator at the end of the buffer and advances topIndex.

Appends number of values from the given iterator at the end of the buffer and advances topIndex.

Attributes

Inherited from:
Buffer
final def appendFromIterator(iterator: Iterator[T]): Buffer.this.type

Appends values from the given iterator at the end of the buffer and advances topIndex.

Appends values from the given iterator at the end of the buffer and advances topIndex.

Attributes

Inherited from:
Buffer
final def appendIterable(iterable: Iterable[T]): Buffer.this.type

Appends values from the given iterable at the end of the buffer and advances topIndex.

Appends values from the given iterable at the end of the buffer and advances topIndex.

Attributes

Inherited from:
Buffer
final def appendSequence(values: IndexedSeq[T]): Buffer.this.type

Appends values from the given sequence at the end of the buffer and advances topIndex.

Appends values from the given sequence at the end of the buffer and advances topIndex.

Attributes

Inherited from:
Buffer
final def appendSlice(slice: Slice[T]): Buffer.this.type

Appends values from the given slice at the end of the buffer and advances topIndex.

Appends values from the given slice at the end of the buffer and advances topIndex.

Attributes

Inherited from:
Buffer
def compose[A](g: A => Int): A => T

Attributes

Inherited from:
Function1
final def contains(value: T): Boolean

Returns true if buffer contains given value.

Returns true if buffer contains given value.

Attributes

Inherited from:
Buffer
final def exists(pred: T => Boolean): Boolean

Returns true if buffer contains value fulfilling the predicate.

Returns true if buffer contains value fulfilling the predicate.

Attributes

Inherited from:
Buffer
final def forward(distance: Int): Buffer.this.type

Moves topIndex value right by the distance.

Moves topIndex value right by the distance.

Attributes

Inherited from:
Buffer
final def get(index: Int): Option[T]

Returns Some value at the index, or None if index outside of range.

Returns Some value at the index, or None if index outside of range.

Attributes

Inherited from:
Buffer
final def head: T

Returns value at the topIndex.

Returns value at the topIndex.

Attributes

Inherited from:
Buffer
final def headOption: Option[T]

Returns Some value at the topIndex or None if empty buffer.

Returns Some value at the topIndex or None if empty buffer.

Attributes

Inherited from:
Buffer
final def init: Buffer.this.type

Returns this buffer without a first element.

Returns this buffer without a first element.

Attributes

Inherited from:
Buffer
final def insert(index: Int, value: T): Buffer.this.type

Shifts content in [index, length) one step to the right and updates value at index.

Shifts content in [index, length) one step to the right and updates value at index.

Attributes

Inherited from:
Buffer
final override def insertArray(index: Int, sourceIndex: Int, insertLength: Int, sourceArray: Array[T]): ArrayBufferLike.this.type

Shift current content to the right starting from indexat the insertLength distance, and copies array chunk into the gap. Sets topIndex to be at least at the end of the new chunk of values.

Shift current content to the right starting from indexat the insertLength distance, and copies array chunk into the gap. Sets topIndex to be at least at the end of the new chunk of values.

Attributes

Definition Classes
Inherited from:
ArrayBufferLike
final def insertFromIterator(index: Int, numberOfValues: Int, iterator: Iterator[T]): Buffer.this.type

Shift current content to the right starting from indexat the min(iterator.length, insertLength) distance, and inserts iterated values into the gap.

Shift current content to the right starting from indexat the min(iterator.length, insertLength) distance, and inserts iterated values into the gap.

  • Sets topIndex to be at least at the end of the new chunk of values.

Attributes

Inherited from:
Buffer
final def insertFromIterator(index: Int, iterator: Iterator[T]): Buffer.this.type

Inserts iterated values into the gap made by shiftjng buffer right, starting from the index.

Inserts iterated values into the gap made by shiftjng buffer right, starting from the index.

  • Sets topIndex to be at least at the end of the new chunk of values.

Attributes

Inherited from:
Buffer
final def insertFromIteratorReverse(index: Int, numberOfValues: Int, iterator: Iterator[T]): Buffer.this.type

Shift current content to the right starting from indexat the min(iterator.length, insertLength) distance, and inserts iterated values into the gap in the reverse order.

Shift current content to the right starting from indexat the min(iterator.length, insertLength) distance, and inserts iterated values into the gap in the reverse order.

  • Sets topIndex to be at least at the end of the new chunk of values.

Attributes

Inherited from:
Buffer
final def insertFromIteratorReverse(index: Int, iterator: Iterator[T]): Buffer.this.type

Inserts iterated values, in the reverse order, into the gap made by shiftjng buffer right, starting from the index.

Inserts iterated values, in the reverse order, into the gap made by shiftjng buffer right, starting from the index.

  • Sets topIndex to be at least at the end of the new chunk of values.

Attributes

Inherited from:
Buffer
final override def insertSlice(index: Int, slice: Slice[T]): ArrayBufferLike.this.type

Shift current content to the right starting from index at the slice.length distance, and copies slice content into the gap. Sets topIndex to be at least at the end of the new chunk of values.

Shift current content to the right starting from index at the slice.length distance, and copies slice content into the gap. Sets topIndex to be at least at the end of the new chunk of values.

Attributes

Definition Classes
Inherited from:
ArrayBufferLike
final def insertValues(index: Int, sourceIndex: Int, numberOfValues: Int, source: Int => T): Buffer.this.type

Shift current content to the right starting from indexat the insertLength distance, iterates over the source indexes and copies values into the gap.

Shift current content to the right starting from indexat the insertLength distance, iterates over the source indexes and copies values into the gap.

  • Sets topIndex to be at least at the end of the new chunk of values.

Attributes

Inherited from:
Buffer
final def isEmpty: Boolean

Is the accessible part of the buffer empty?

Is the accessible part of the buffer empty?

Attributes

Inherited from:
Buffer
final def iterator: Iterator[T]

Returns an iterator over actual buffer values, starting from the zero index up.

Returns an iterator over actual buffer values, starting from the zero index up.

Attributes

Note

does not copy buffer values,

Inherited from:
Buffer
final def last: T

Returns value at the zero index.

Returns value at the zero index.

Attributes

Inherited from:
Buffer
final def lastOption: Option[T]

Returns Some value at the zero index, or None if empty buffer.

Returns Some value at the zero index, or None if empty buffer.

Attributes

Inherited from:
Buffer
final def length: Int

Length of the accessible part of the buffer.

Length of the accessible part of the buffer.

Attributes

Inherited from:
Buffer
final def map[K](f: T => K): Iterable[K]

Iterable representing lazily mapped values of this buffer at the time of access.

Iterable representing lazily mapped values of this buffer at the time of access.

Value parameters

f

map function

Attributes

Inherited from:
Buffer
final def mapInPlace(f: T => T): Buffer.this.type

Updates in-place all values in the range [0,length) using the function.

Updates in-place all values in the range [0,length) using the function.

Value parameters

f

map function

Attributes

Inherited from:
Buffer
final def modify(index: Int, map: T => T): Buffer.this.type

Updates value at the provided index using the function. Index must fall within range [0,length).

Updates value at the provided index using the function. Index must fall within range [0,length).

Value parameters

index

value's index

map

map function

Attributes

Throws
IndexOutOfBoundsException

if index lower than zero.

Inherited from:
Buffer
final def modifyAll(map: T => T): Buffer.this.type

Updates all values in the range [0,length) using the function.

Updates all values in the range [0,length) using the function.

Value parameters

map

map function

Attributes

Inherited from:
Buffer
final def modifyAllWhen(map: T => T, pred: T => Boolean): Buffer.this.type

Updates all accepted values in the range [0,length) using the function.

Updates all accepted values in the range [0,length) using the function.

Value parameters

map

map function

pred

filter function

Attributes

Inherited from:
Buffer
final def modifyRange(fromIndex: Int, toIndex: Int, map: T => T): Buffer.this.type

Updates values in the range [startIndex,toIndex)^^[0,length) using the function. One of {startIndex,toIndex} must fall within range [0,length).

Updates values in the range [startIndex,toIndex)^^[0,length) using the function. One of {startIndex,toIndex} must fall within range [0,length).

Value parameters

fromIndex

index of the first value inclusive

map

map function

toIndex

index of the last value exclusive

Attributes

Throws
IndexOutOfBoundsException

if index lower than zero.

Inherited from:
Buffer
final def modifyRangeWhen(fromIndex: Int, toIndex: Int, map: T => T, pred: T => Boolean): Buffer.this.type

Updates values in the range [startIndex,toIndex)^^[0,length) using the function. One of {startIndex,toIndex} must fall within range [0,length).

Updates values in the range [startIndex,toIndex)^^[0,length) using the function. One of {startIndex,toIndex} must fall within range [0,length).

Value parameters

fromIndex

index of the first value inclusive

map

map function

pred

filter function

toIndex

index of the last value exclusive

Attributes

Throws
IndexOutOfBoundsException

if index lower than zero.

Inherited from:
Buffer
final override def moveRangeLeft(fromIndex: Int, toIndex: Int, distance: Int): ArrayBufferLike.this.type

Moves values in [fromIndex,toIndex) to the left at a distance, to become [fromIndex - distance, toIndex - distance), and moves right any existing values in [fromIndex - distance, fromIndex) to become [toIndex - distance, toIndex). Shifts right first if distance > fromIndex. Ignores negative distance and values outside of [0,length). Moves topIndex if affected.

Moves values in [fromIndex,toIndex) to the left at a distance, to become [fromIndex - distance, toIndex - distance), and moves right any existing values in [fromIndex - distance, fromIndex) to become [toIndex - distance, toIndex). Shifts right first if distance > fromIndex. Ignores negative distance and values outside of [0,length). Moves topIndex if affected.

Attributes

Definition Classes
Inherited from:
ArrayBufferLike
final override def moveRangeRight(fromIndex: Int, toIndex: Int, distance: Int): ArrayBufferLike.this.type

Moves values in [fromIndex,toIndex) to the right at a distance, to become [fromIndex + distance, toIndex + distance), and moves left any existing values in [toIndex, toIndex + distance) to become [fromIndex, fromIndex + distance). Ignores negative distance and values outside of [0,length). Moves topIndex if affected.

Moves values in [fromIndex,toIndex) to the right at a distance, to become [fromIndex + distance, toIndex + distance), and moves left any existing values in [toIndex, toIndex + distance) to become [fromIndex, fromIndex + distance). Ignores negative distance and values outside of [0,length). Moves topIndex if affected.

Attributes

Definition Classes
Inherited from:
ArrayBufferLike
final def nonEmpty: Boolean

Is the accessible part of the buffer non empty?

Is the accessible part of the buffer non empty?

Attributes

Inherited from:
Buffer
final override def optimize(): ArrayBufferLike.this.type

Attempts to optimize buffer storage, if needed.

Attempts to optimize buffer storage, if needed.

Attributes

Definition Classes
Inherited from:
ArrayBufferLike
final def peek(offset: Int): T

Returns value at the topIndex - offset.

Returns value at the topIndex - offset.

Attributes

Inherited from:
Buffer
final def peek: T

Returns value at the topIndex.

Returns value at the topIndex.

Attributes

Inherited from:
Buffer
final def peekOption(offset: Int): Option[T]

Returns value at the topIndex - offset.

Returns value at the topIndex - offset.

Attributes

Inherited from:
Buffer
final def pop: T

Returns value at the topIndex, and moves topIndex back.

Returns value at the topIndex, and moves topIndex back.

Attributes

Inherited from:
Buffer
final def push(value: T): Buffer.this.type

Appends value to the topIndex. Same as append

Appends value to the topIndex. Same as append

Attributes

Inherited from:
Buffer
final def remove(index: Int): Buffer.this.type

Removes value at index and shifts content in [index+1, length) to the left.

Removes value at index and shifts content in [index+1, length) to the left.

Attributes

Inherited from:
Buffer
final def removeRange(fromIndex: Int, toIndex: Int): Buffer.this.type

Removes values in the range [fromIndex, toIndex) and shifts content in [toIndex, length) to the left.

Removes values in the range [fromIndex, toIndex) and shifts content in [toIndex, length) to the left.

Attributes

Inherited from:
Buffer
final def removeWhen(pred: T => Boolean): Buffer.this.type

Removes values matching the predicate.

Removes values matching the predicate.

Attributes

Inherited from:
Buffer
final override def replaceFromArray(index: Int, sourceIndex: Int, replaceLength: Int, sourceArray: Array[T]): ArrayBufferLike.this.type

Replaces current values in the range [index, index + replaceLength) with values of the array range [sourceIndex, sourceIndex + replaceLength).

Replaces current values in the range [index, index + replaceLength) with values of the array range [sourceIndex, sourceIndex + replaceLength).

Attributes

Definition Classes
Inherited from:
ArrayBufferLike
final def replaceFromIterator(index: Int, numberOfValues: Int, iterator: Iterator[T]): Buffer.this.type

Replaces current values in the range [index, index + min(iterator.length, replaceLength) ) with values returned from the iterator.

Replaces current values in the range [index, index + min(iterator.length, replaceLength) ) with values returned from the iterator.

Attributes

Inherited from:
Buffer
final def replaceFromIteratorReverse(index: Int, numberOfValues: Int, iterator: Iterator[T]): Buffer.this.type

Replaces current values in the range [index, index + min(iterator.length, replaceLength)) with values returned from the iterator in the reverse order.

Replaces current values in the range [index, index + min(iterator.length, replaceLength)) with values returned from the iterator in the reverse order.

Attributes

Inherited from:
Buffer
final override def replaceFromSlice(index: Int, slice: Slice[T]): ArrayBufferLike.this.type

Replaces current values in the range [index, index + slice.length) with values of the slice.

Replaces current values in the range [index, index + slice.length) with values of the slice.

Attributes

Definition Classes
Inherited from:
ArrayBufferLike
final def replaceValues(index: Int, sourceIndex: Int, numberOfValues: Int, source: Int => T): Buffer.this.type

Replaces current values in the range [index, index + replaceLength) with values returned by the function when iterating argument in the range [sourceIndex, sourceIndex + replaceLength).

Replaces current values in the range [index, index + replaceLength) with values returned by the function when iterating argument in the range [sourceIndex, sourceIndex + replaceLength).

Attributes

Inherited from:
Buffer
final def reset: Int

Resets buffer, sets topIndex to -1.

Resets buffer, sets topIndex to -1.

  • Does not clear existing values.

Attributes

Returns

previous topIndex

Inherited from:
Buffer
final def reverseIterator: Iterator[T]

Returns a reverse iterator over actual buffer values, starting from the topIndex down.

Returns a reverse iterator over actual buffer values, starting from the topIndex down.

Attributes

Inherited from:
Buffer
final def rewind(distance: Int): Buffer.this.type

Moves topIndex value left by the distance.

Moves topIndex value left by the distance.

Attributes

Inherited from:
Buffer
final def set(index: Int): Buffer.this.type

Sets topIndex value.

Sets topIndex value.

Attributes

Inherited from:
Buffer
final override def shiftLeft(index: Int, distance: Int): ArrayBufferLike.this.type

Moves values [index, length) left to [index-distance, length - distance). Effectively removes range (index-distance, index]. Ignores negative distance. Moves topIndex if affected.

Moves values [index, length) left to [index-distance, length - distance). Effectively removes range (index-distance, index]. Ignores negative distance. Moves topIndex if affected.

Attributes

Definition Classes
Inherited from:
ArrayBufferLike
final override def shiftRight(index: Int, distance: Int): ArrayBufferLike.this.type

Moves values [index, length) right to [index+distance, length + distance). Effectively creates a new range [index, index+distance). Ignores negative distance. Does not clear existing values inside [index, index+distance). Moves topIndex if affected.

Moves values [index, length) right to [index+distance, length + distance). Effectively creates a new range [index, index+distance). Ignores negative distance. Does not clear existing values inside [index, index+distance). Moves topIndex if affected.

Attributes

Definition Classes
Inherited from:
ArrayBufferLike
final def store(value: T): Buffer.this.type

Replace value at the topIndex.

Replace value at the topIndex.

Attributes

Inherited from:
Buffer
final def swap(first: Int, second: Int): Buffer.this.type

Swap two values at the provided indexes. Value at first becomes value at second, and vice versa.

Swap two values at the provided indexes. Value at first becomes value at second, and vice versa.

  • Does nothing if any index falls outside [0,length) or if indexes are equal.

Attributes

Inherited from:
Buffer
final override def swapRange(first: Int, second: Int, swapLength: Int): ArrayBufferLike.this.type

Swap values in range [first, first + swapLength) with values in range [second, second + swapLength]

Swap values in range [first, first + swapLength) with values in range [second, second + swapLength]

  • Does nothing if any index falls outside [0,length), or if indexes are equal.
  • if [first, first + swapLength) overlaps with [second, second + swapLength) then the later overwrites the former.

Attributes

Definition Classes
Inherited from:
ArrayBufferLike
final def tail: Buffer.this.type

Returns this buffer after decrementing topIndex .

Returns this buffer after decrementing topIndex .

Attributes

Inherited from:
Buffer
final override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
ArrayBufferLike -> Function1 -> Any
Inherited from:
ArrayBufferLike
final def top: Int

Returns topIndex value.

Returns topIndex value.

Attributes

Inherited from:
Buffer
final def touch(index: Int): Buffer.this.type

Sets topIndex value if lower than index, otherwise keeps existing.

Sets topIndex value if lower than index, otherwise keeps existing.

Attributes

Inherited from:
Buffer
final def trim(size: Int): Buffer.this.type

Trims the buffer, if needed, to have at most the size.

Trims the buffer, if needed, to have at most the size.

Attributes

Inherited from:
Buffer
final override def update(index: Int, value: T): ArrayBufferLike.this.type

Updates value at the provided index. Alters underlying array if necessary.

Updates value at the provided index. Alters underlying array if necessary.

Attributes

Throws
IndexOutOfBoundsException

if index lower than zero.

Definition Classes
Inherited from:
ArrayBufferLike