extern crate alloc;
use alloc::vec::Vec;
use num_complex::Complex;
use num_traits::Float;
pub trait Taps: Send {
type TapType;
fn num_taps(&self) -> usize;
fn get(&self, index: usize) -> Self::TapType;
}
impl<const N: usize, T> Taps for [Complex<T>; N]
where
T: Float + Send + Sync + Copy,
{
type TapType = Complex<T>;
fn num_taps(&self) -> usize {
N
}
fn get(&self, index: usize) -> Complex<T> {
debug_assert!(index < self.num_taps());
unsafe { *self.get_unchecked(index) }
}
}
impl<const N: usize, T> Taps for &[Complex<T>; N]
where
T: Float + Send + Sync + Copy,
{
type TapType = Complex<T>;
fn num_taps(&self) -> usize {
N
}
fn get(&self, index: usize) -> Complex<T> {
debug_assert!(index < self.num_taps());
unsafe { *self.get_unchecked(index) }
}
}
impl<const N: usize> Taps for [f32; N] {
type TapType = f32;
fn num_taps(&self) -> usize {
N
}
fn get(&self, index: usize) -> f32 {
debug_assert!(index < self.num_taps());
unsafe { *self.get_unchecked(index) }
}
}
impl<const N: usize> Taps for &[f32; N] {
type TapType = f32;
fn num_taps(&self) -> usize {
N
}
fn get(&self, index: usize) -> f32 {
debug_assert!(index < self.num_taps());
unsafe { *self.get_unchecked(index) }
}
}
impl<const N: usize> Taps for [f64; N] {
type TapType = f64;
fn num_taps(&self) -> usize {
N
}
fn get(&self, index: usize) -> f64 {
debug_assert!(index < self.num_taps());
unsafe { *self.get_unchecked(index) }
}
}
impl<const N: usize> Taps for &[f64; N] {
type TapType = f64;
fn num_taps(&self) -> usize {
N
}
fn get(&self, index: usize) -> f64 {
debug_assert!(index < self.num_taps());
unsafe { *self.get_unchecked(index) }
}
}
impl<T> Taps for Vec<T>
where
T: Send + Sync + Copy,
{
type TapType = T;
fn num_taps(&self) -> usize {
self.len()
}
fn get(&self, index: usize) -> T {
debug_assert!(index < self.num_taps());
unsafe { *self.get_unchecked(index) }
}
}