Struct jagged_array::Jagged2 [] [src]

pub struct Jagged2<T> { /* fields omitted */ }

2-dimensional jagged array type. It's equivalent to a Box<Box<[mut T]>>, but where all array data is stored contiguously and fewer allocations are performed.

Note that no dimension of the array can be modified after creation.

Jagged arrays can be created via the Jagged2Builder type or the from_iter method.

Methods

impl<T> Jagged2<T>
[src]

Index into the jagged array. The index is given in (Major, Minor) form, i.e. (row, column) or (outer, inner).

Example

use std::iter::FromIterator;
use jagged_array::Jagged2;
let a = Jagged2::from_iter(vec![
    vec![1, 2, 3],
    vec![4],
    vec![],
    vec![5, 6],
]);
assert_eq!(a.get([1, 0]), Some(&4));
assert_eq!(a.get([2, 0]), None);

Index into the jagged array. The index is given in (Major, Minor) form, i.e. (row, column) or (outer, inner).

Example

use std::iter::FromIterator;
use jagged_array::Jagged2;
let mut a = Jagged2::from_iter(vec![
    vec![1, 2, 3],
    vec![4],
    vec![],
    vec![5, 6],
]);
assert_eq!(a.get([1, 0]), Some(&4));
*a.get_mut([1, 0]).unwrap() = 11;
assert_eq!(a.get([1, 0]), Some(&11));

Retrieve the given row as a contiguous slice of memory.

Example

use std::iter::FromIterator;
use jagged_array::Jagged2;
let a = Jagged2::from_iter(vec![
    vec![1, 2, 3],
    vec![4],
    vec![],
    vec![5, 6],
]);
assert_eq!(a.get_row(3), Some(&[5, 6][..]));

Retrieve the given row as a contiguous slice of mutable memory.

Example

use std::iter::FromIterator;
use jagged_array::Jagged2;
let mut a = Jagged2::from_iter(vec![
    vec![1, 2, 3],
    vec![4],
    vec![],
    vec![5, 6],
]);
assert_eq!(a.get_row_mut(3), Some(&mut[5, 6][..]));
a.get_row_mut(3).unwrap()[1] = 11;
assert_eq!(a[[3, 1]], 11);

Return a slice over the entire storage area.

Example

use std::iter::FromIterator;
use jagged_array::Jagged2;
let a = Jagged2::from_iter(vec![
    vec![1, 2, 3],
    vec![4],
    vec![],
    vec![5, 6],
]);
assert_eq!(a.as_flat_slice(), &[1, 2, 3, 4, 5, 6][..]);

Return a mutable slice over the entire storage area.

Example

use std::iter::FromIterator;
use jagged_array::Jagged2;
let mut a = Jagged2::from_iter(vec![
    vec![1, 2, 3],
    vec![4],
    vec![],
    vec![5, 6],
]);
assert_eq!(a.as_flat_slice()[3], 4);
a.as_flat_slice_mut()[3] = 33;
assert_eq!(a[[1, 0]], 33);

Return the total number of T held in the array.

This is generally a constant-time operation, but if T is a zero-sized type then the time complexity is proportional to the number of rows in the array.

Example

use std::iter::FromIterator;
use jagged_array::Jagged2;
let a = Jagged2::from_iter(vec![
    vec![1, 2, 3],
    vec![4],
    vec![],
    vec![5, 6],
]);
assert_eq!(a.flat_len(), 6);

Return the number of rows held in the array.

Example

use std::iter::FromIterator;
use jagged_array::Jagged2;
let a = Jagged2::from_iter(vec![
    vec![1, 2, 3],
    vec![4],
    vec![],
    vec![5, 6],
]);
assert_eq!(a.len(), 4);

Return true if the array holds no items. Semantically equivalent to jagged2.len() == 0.

Create a streaming iterator over the rows of this array. Lifetime restrictions prevent implementing std::iter::Iterator for this type, however a streaming iterator provides similar features except that the lifetime of the items it yields is tied to the lifetime of the iterator itself.

Example

use std::iter::FromIterator;
use jagged_array::Jagged2;
use streaming_iterator::StreamingIterator;

let a = Jagged2::from_iter(vec![
    vec![1, 2, 3],
    vec![4],
]);
let mut iter = a.stream();
while let Some(row) = iter.next() {
    println!("row: {:?}", row);
}

Consumes self and returns the underlying storage (identical to as_flat_slice_mut, but owned).

The slice can optionally be turned into a vector by calling slice::into_vec() on the result.

Trait Implementations

impl<T> Index<[usize; 2]> for Jagged2<T>
[src]

The returned type after indexing

Index into the jagged array. The index is given in (Major, Minor) form, i.e. (row, column) or (outer, inner). array[[0, 0]] is adjacent to array[[0, 1]] in memory but not necessarily to array[[1, 0]].

impl<T> Drop for Jagged2<T>
[src]

A method called when the value goes out of scope. Read more

impl<T> Default for Jagged2<T>
[src]

Returns the "default value" for a type. Read more

impl<T> Debug for Jagged2<T> where
    T: Debug
[src]

Formats the value using the given formatter.

impl<T, ICol> FromIterator<ICol> for Jagged2<T> where
    ICol: IntoIterator<Item = T>, 
[src]

Allow construction from any type that behaves like [[T]].

Example

use std::iter::FromIterator;
use jagged_array::Jagged2;
let a = Jagged2::from_iter(vec![
    vec![1, 2, 3],
    vec![4],
    vec![],
    vec![5, 6],
]);
assert_eq!(a.len(), 4); // 4 rows
assert_eq!(a.as_flat_slice(), &[1, 2, 3, 4, 5, 6][..]); // contiguous view
assert_eq!(a.get_row(3), Some(&[5, 6][..])); // third row
assert_eq!(a[[0, 1]], 2); // first row, second column

impl<T> Clone for Jagged2<T> where
    T: Clone
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T> PartialEq for Jagged2<T> where
    T: PartialEq
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T> Eq for Jagged2<T> where
    T: Eq
[src]

impl<T> Hash for Jagged2<T> where
    T: Hash
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<T> Serialize for Jagged2<T> where
    T: Serialize
[src]

Serialize this value into the given Serde serializer. Read more

impl<'de, T> Deserialize<'de> for Jagged2<T> where
    T: Deserialize<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more