This crate provides a jagged array, i.e. a type that is semantically equivalent to
Box<[Box<[T]>]>
, but implemented with better memory locality and fewer heap allocations.
Example
extern crate jagged_array;
extern crate streaming_iterator;
use FromIterator;
use ;
use StreamingIterator;
// Create a builder object for the array, and append some data.
// Each `extend` call builds another row.
let mut builder = new;
builder.extend; // row 0 = [1, 2, 3]
builder.extend; // row 1 = [4]
builder.extend; // row 2 = []
builder.extend; // row 3 = [5, 6]
// Finalize the builder into a non-resizable jagged array.
let mut a: = builder.into;
// Alternatively, we could have created the same array from a Vec<Vec<T>> type:
let alt_form = from_iter;
assert_eq!;
// Indexing is done in [row, column] form and supports `get` and `get_mut` variants.
assert_eq!;
*a.get_mut.unwrap = 11;
assert_eq!;
// Whole rows can also be accessed and modified
assert_eq!;
a.get_row_mut.unwrap = 11;
// Note that although elements are modifiable, the structure is not;
// items cannot be inserted into rows, nor can new rows be added.
// Iteration via `StreamingIterator`s. See the docs for more detail.
let mut iter = a.stream;
while let Some = iter.next
Documentation
Documentation can be found on docs.rs
Benchmarks
)
)
)
)
)
)
)
)
*_jag
indicates runtime for the Jagged2<u32>
implementation,
*_vec
indicates runtime for Vec<Vec<u32>>
.
See benches/jagged2.rs for more details.
License
The code in this repository is licensed under either of
- Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this repository by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.