use crate::linear_algebra::Vector;
pub trait Array {
type Element;
type Vector: Vector;
fn length(&self) -> usize;
fn at_ref(&self, index: usize) -> &Self::Element;
fn at_mut(&mut self, index: usize) -> &mut Self::Element;
}
macro_rules! array_impl_for {
($v:expr) => {
impl<T> Array for [T; $v] {
type Element = T;
type Vector = [f64; $v];
fn length(&self) -> usize {
$v
}
fn at_ref(&self, index: usize) -> &T {
&self[index]
}
fn at_mut(&mut self, index: usize) -> &mut T {
&mut self[index]
}
}
};
}
array_impl_for! { 1 }
array_impl_for! { 2 }
array_impl_for! { 3 }
array_impl_for! { 4 }
array_impl_for! { 5 }
array_impl_for! { 6 }
array_impl_for! { 7 }
array_impl_for! { 8 }
array_impl_for! { 9 }
array_impl_for! { 10 }
array_impl_for! { 11 }
array_impl_for! { 12 }
array_impl_for! { 13 }
array_impl_for! { 14 }
array_impl_for! { 15 }
array_impl_for! { 16 }
array_impl_for! { 17 }
array_impl_for! { 18 }
array_impl_for! { 19 }
array_impl_for! { 20 }
array_impl_for! { 21 }
array_impl_for! { 22 }
array_impl_for! { 23 }
array_impl_for! { 24 }
array_impl_for! { 25 }
array_impl_for! { 26 }
array_impl_for! { 27 }
array_impl_for! { 28 }
array_impl_for! { 29 }
array_impl_for! { 30 }
array_impl_for! { 31 }
array_impl_for! { 32 }