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.
Member Variables
Name | Description |
---|---|
values:Type[_] | Elements. |
offsets:Integer[_] | Offset into values for each row. |
sizes:Integer[_] | Number of columns in each row. |
Member Slices
Name | Description |
---|---|
[...] | Reference to an element. |
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. |
from | First serial index of a row. |
to | Last serial index of a row. |
serial | Serial index of row and column. |
Member Slice Details
operator [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.
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.
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.
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
.
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.
walk
function walk() -> Iterator<Type[_]>
Obtain an iterator over rows.
Return: an iterator across entire rows from top to bottom.
function walk(i:Integer) -> Iterator<Type>
Obtain an iterator over columns.
- i: Row.
Return: an iterator across the elements of the given row, from left to right.