Skip to content

Array


final class Array<Type>

Resizeable array with constant-time random access.

  • Type: Element type. Must be default-constructible.

Member Variables

Name Description
values:Type[_] Elements.

Member Functions

Name Description
size Number of elements.
empty Is this empty?
clear Clear all elements.
get Get an element.
set Set an element.
front Get the first element.
back Get the last element.
pushFront Insert an element at the front.
pushFront Insert a new default-constructed element at the front and return it.
pushBack Insert an element at the back.
pushBack Insert a new default-constructed element at the back and return it.
popFront Remove the first element.
popBack Remove the last element.
insert Insert a new element.
erase Erase an element.
erase Erase multiple elements.
walk Obtain an iterator.
toArray Convert to array.
fromArray Convert from array.

Member Function Details

back

function back() -> Type

Get the last element.

clear

function clear()

Clear all elements.

empty

function empty() -> Boolean

Is this empty?

erase

function erase(i:Integer)

Erase an element.

  • i: Position.

The size decreases by one.

function erase(i:Integer, n:Integer)

Erase multiple elements.

  • i: Position.
  • n: Number of elements.

The size decreases by n.

fromArray

function fromArray(x:Type[_])

Convert from array.

front

function front() -> Type

Get the first element.

get

function get(i:Integer) -> Type

Get an element.

  • i: Position.

insert

function insert(i:Integer, x:Type)

Insert a new element.

  • i: Position.
  • x: Value.

Inserts the new element immediately before the current element at position i. To insert at the back of the container, use a position that is one more than the current size, or pushBack().

popBack

function popBack()

Remove the last element.

popFront

function popFront()

Remove the first element.

pushBack

function pushBack(x:Type)

Insert an element at the back.

  • x: Value.

function pushBack() -> Type

Insert a new default-constructed element at the back and return it.

pushFront

function pushFront(x:Type)

Insert an element at the front.

  • x: Value.

function pushFront() -> Type

Insert a new default-constructed element at the front and return it.

set

function set(i:Integer, x:Type)

Set an element.

  • i: Position.
  • x: Value.

size

function size() -> Integer

Number of elements.

toArray

function toArray() -> Type[_]

Convert to array.

walk

function walk() -> Iterator<Type>

Obtain an iterator.

Return: an iterator across elements in forward order.