Skip to content

RaggedArray

class RaggedArray<Type> < Object

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

Member Variables

Name Description
values:Type[_] Elements.
offsets:Integer[_] Offset into values for each row.
ncols:Integer[_] Number of columns in each row.
nrows:Integer Number of rows.
nelements:Integer Number of elements.

Member Functions

Name Description
empty Is this empty?
clear Clear all 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.
pushBack Add a new row at the back.
pushBack Add a new element to the end of a row.
shrink Decrease the number of rows.
shrink Decrease the number of columns in a row.
enlarge Increase the number of rows.
enlarge Increase the number of columns in a row.
from First serial index of a row.
to Last serial index of a row.
serial Serial index of row and column.

Member Fibers

Name Description
walk Iterate over the rows.
walk Iterate over the columns of a row.

Member Function Details

clear

function clear()

Clear all elements.

empty

function empty() -> Boolean

Is this empty?

enlarge

function enlarge(n:Integer)

Increase the number of rows.

  • n: Number of rows.

The current contents is preserved.

function enlarge(i:Integer, n:Integer, x:Type)

Increase the number of columns in a row.

  • i: Row.
  • n: Number of columns.
  • x: Value for new elements.

The current contents of the row is preserved.

from

function from(i:Integer) -> Integer

First serial index of a row.

  • i: Row.

get

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

Get an element.

  • i: Row.
  • j: Column.

function get(i:Integer) -> Type[_]

Get a row.

  • i: Row.

pushBack

function pushBack()

Add a new row at the back.

function pushBack(i:Integer, x:Type)

Add a new element to the end of a row.

  • i: Row.
  • x: Value.

serial

function serial(i:Integer, j:Integer) -> Integer

Serial index of row and column.

  • i: Row.
  • j: Column.

set

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

Set an element.

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

function set(i:Integer, x:Type[_])

Set a row.

  • i: Row.
  • x: Values.

The number of columns in the row must match the number of columns in x. Use shrink or enlarge beforehand if necessary.

shrink

function shrink(n:Integer)

Decrease the number of rows.

  • n: Number of rows.

The current contents is preserved.

function shrink(i:Integer, n:Integer)

Decrease the number of columns in a row.

  • i: Row.
  • n: Number of columns.

The current contents of the row is preserved.

size

function size() -> Integer

Number of rows.

function size(i:Integer) -> Integer

Number of elements for a given row.

  • i: Row.

to

function to(i:Integer) -> Integer

Last serial index of a row.

  • i: Row.

Member Fiber Details

walk

fiber walk() -> Type[_]

Iterate over the rows.

Return: a fiber object that yields each row in forward order.

fiber walk(i:Integer) -> Type

Iterate over the columns of a row.

  • i: Row.

Return: a fiber object that yields each row in forward order.