Skip to content

RaggedArray


final class RaggedArray<Type>

Two-dimensional array where each row has a varying length. Internally, this is stored in one contiguous array for constant-time random access.

  • Type Element type. Must be default-constructible.

Slices

Name Description
[...] Reference to an element.

Member Variables

Name Description
values:Array<Array<Type>> Elements.

Member Functions

Name Description
empty Is this empty?
clear Clear all rows.
count Number of elements.
size Number of rows.
size Number of elements for a given row.
get Get an element.
get Get a row.
set Set an element.
set Set a row.
popFront Remove the front row.
popFront Remove the front element from a specified row.
pushBack Add a new row at the back.
pushBack Add an element to the back of a specified row.
pushBack Add a new default-constructed element to the back of the specified row, and return the element.
walk Obtain an iterator over rows.
walk Obtain an iterator over columns.

Member Slice Details

[i:Integer, j:Integer] -> Type

Reference to an element.

  • i Row.
  • j Column.

Member Function Details

clear

function clear()

Clear all rows.

count

function count() -> Integer

Number of elements.

empty

function empty() -> Boolean

Is this empty? A RaggedArray is considered empty if it has no rows. A RaggedArray with one or more rows is not considered empty, even if those rows have no elements.

get

function get(i:Integer, j:Integer) -> Type

Get an element.

  • i Row.
  • j Column.

function get(i:Integer) -> Array<Type>

Get a row.

  • i Row.

popFront

function popFront()

Remove the front row.

function popFront(i:Integer)

Remove the front element from a specified row.

  • i Row.

pushBack

function pushBack()

Add a new row at the back.

function pushBack(i:Integer, x:Type)

Add an element to the back of a specified row.

  • i Row.
  • x Value.

function pushBack(i:Integer) -> Type

Add a new default-constructed element to the back of the specified row, and return the element.

set

function set(i:Integer, j:Integer, x:Type)

Set an element.

  • i Row.
  • j Column.
  • x Value.

function set(i:Integer, x:Array<Type>)

Set a row.

  • i Row.
  • x Values.

size

function size() -> Integer

Number of rows.

function size(i:Integer) -> Integer

Number of elements for a given row.

  • i Row.

walk

function walk() -> Iterator<Array<Type>>

Obtain an iterator over rows.

Returns an iterator across entire rows from top to bottom.

function walk(i:Integer) -> Iterator<Type>

Obtain an iterator over columns.

  • i Row.

Returns an iterator across the elements of the given row, from left to right.