Triangle Matrix
A simple library for representing flat data structures as a triangle matrix.
Provides the TriangleIndex
trait that provides an abstraction of triangle
matrix indexing operations for a one dimensional collection. All operations
are delegated to the inner collection using Deref
and DerefMut
. Requires
delegating the length of an axis, n
, using the TriangleType
trait.
Example
use PhantomData;
use ;
use *;
// Create a wrapper storing the length of an axis and the collection.
;
// Implement `Deref` and `DerefMut`, delegating `Deref::Target` to the vector.
// Delegate `n` to the `usize` field and specify `Ty` as the triangle type.
// An abstraction of an `4 * 4` triangle matrix where the elements are the usize indices.
let n = 4;
let v = Vec from_iter;
// Represent the vector as an upper triangle matrix.
let mut m: = VecTri;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
*m.get_element_mut = 10;
*m.get_element_mut = 11;
// Thanks to `Deref`, we can index into the underlying vector.
assert_eq!;