Crates.io | toodee |
lib.rs | toodee |
version | 0.5.0 |
source | src |
created_at | 2020-05-25 23:53:53.215032 |
updated_at | 2023-09-09 20:54:29.223406 |
description | A lightweight 2D wrapper around a Vec. |
homepage | |
repository | https://github.com/antonmarsden/toodee |
max_upload_size | |
id | 245904 |
size | 205,053 |
TooDee
is a lightweight and high performance two-dimensional wrapper around a growable Vec
.
TooDeeView
and TooDeeViewMut
allow you create two-dimensional wrappers around a slice.
data()
and data_mut()
.view()
and view_mut()
.get_unchecked(Coordinate)
and get_unchecked_row(usize)
for faster (unsafe) access to cells or rows.TooDee
and TooDeeViewMut
structs - see below for how this pattern can be extended.let my_row = toodee[row]; my_row[col] = val;
.Coordinate
if you prefer, e.g., toodee[(col, row)] = val
.&toodee[row]
.rows()
, rows_mut()
, col()
, col_mut()
, cells()
, cells_mut()
.#[no_std]
compliant.TooDeeView
from a &[T]
, or a TooDeeViewMut
from a &mut [T]
.insert_col()
, remove_col()
, insert_row()
, and remove_row()
implementations with good performance.copy
, included by defaultThe CopyOps
trait provides 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()
.
translate
, included by defaultThe 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.sort
, included by defaultThe SortOps
trait provides efficient implementations of:
sort_by_row()
operations, with stable and unstable variants.sort_by_col()
operations, with stable and unstable variants.serde
, included by defaultSerialization and deserialization of TooDee
objects.
TooDeeView
and TooDeeViewMut
can be serialized, but must be deserialized into a TooDee
structure.
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.
Additionally, you can override the trait's default implementation if necessary.
The implementation of a new trait could look something like:
pub trait FooOps<T> : TooDeeOpsMut<T> {
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<T> FooOps<T> for TooDeeViewMut<'_, T> {}
impl<T> FooOps<T> for TooDee<T> {}
Once the implementations are available, just call the methods, e.g.,
let bar = my_toodee.foo();
let bar_view = my_toodee_mut_view.foo();
Happy coding :smile:
Similar libraries do exist, but they lacked either performance, flexibility, or functionality.
Here's a small feature comparison chart:
Storage order | Structs supported | Growable? | Mutable views? | Raw data access? | Iterate over row slices? | Notes | |
---|---|---|---|---|---|---|---|
toodee::TooDee | Row-major | Anything (Sized ) | Yes | Yes | Yes | Yes | |
image::ImageBuffer | Row-major | image::Pixel | No | No | Yes | No | Good for image processing - see the imageproc crate. |
image::SubImage | Row-major | image::Pixel | No | Yes | No | No | |
grid::Grid | Row-major | Clone | Yes | No | Yes | No | Similar to TooDee , but not as functionally rich. |
array2d::Array2D | Row-major | Clone | No | No | No | No | |
imgref::Img | Row-major | Anything (Sized ) | No | Yes | Yes | Yes | |
nalgebra::Matrix | Column-major | Scalar | Yes | Yes | Yes | No | Use this for vector/matrix math. |
Licensed under either of
at your option.
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.