Build Status Current Version Documentation License: MIT OR Apache-2.0

toodee

TooDee is a lightweight and high performance two-dimensional wrapper around a Vec.

Core features

Additional Algorithms

CopyOps (copy feature, included by default)

Various operations that copy data within the same 2D array, or copy data from one array to another. Many of these operations are named like their slice counterparts, e.g., copy_from_slice() or copy_from_toodee().

TranslateOps (translate feature, included by default)

The TranslateOps trait provides common translation algorithms, including: - translate_with_wrap(), a way to shift data around vertically and horizontally. - flip_rows(), i.e., a mirror translation of data about the center row. - flip_cols(), i.e., a mirror translation of data about the center column.

SortOps (sort feature, included by default)

The SortOps trait provides efficient implementations of: - sort_by_row() operations, with stable and unstable variants. - sort_by_col() operations, with stable and unstable variants.

Build Your Own 2D Algorithms

Traits such as SortOps contain additional algorithms. These traits are defined by extending the TooDeeOpsMut trait, which has been implemented for TooDee and TooDeeViewMut. I recommend taking the same approach because the algorithms you implement will then work on both structs. This may not seem useful at first glance, but a great use case would be sorting a spreadsheet by column. If each column had a header row, you'd want to exclude that header row from sorting. You can achieve this by creating a TooDeeViewMut and sorting the view.

The implementation of your new trait could look something like:

``` pub trait FooOps : TooDeeOpsMut {

fn foo(&mut self) -> Bar {
    ...
    return bar;
}

} ```

The above code would provide a default foo() implementation that could be overridden if required. Then it's simply a matter of stating that both TooDee and TooDeeOpsMut implement FooOps:

``` impl FooOps for TooDeeViewMut<'_, T> {}

impl FooOps for TooDee {} ```

Then it's just a matter of calling the method, e.g.,

let bar = my_toodee.foo(); let bar_view = my_toodee_mut_view.foo();

Happy coding :)

TODO

Motivation

Similar libraries do exist, but they lacked either performance, flexibility, or functionality.

Here's a small feature comparison chart:

Storage orderStructs supportedGrowable?Mutable views?Raw data access?Iterate over row slices?Notes
toodee::TooDeeRow-majorAnything (`Sized`)YesYesYesYes
image::ImageBufferRow-majorimage::PixelNoNoYesNoGood for image processing - see the imageproc crate.
image::SubImageRow-majorimage::PixelNoYesNoNo
grid::GridRow-majorCloneYesNoYesNoSimilar to TooDee, but not as functionally rich.
array2d::Array2DRow-majorCloneNoNoNoNo
imgref::ImgRow-majorAnything (`Sized`)NoYesYesNo
nalgebra::MatrixColumn-majorScalarYesYesYesNoUse this for vector/matrix math.

Goals

Non-goals

Limitations

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.