use bitvec::prelude::*;
use bitvec::BitArr;
use core::mem::MaybeUninit;
use phenotype_internal::Phenotype;
pub struct FixedPod<T: Phenotype, const N: usize> {
tags_init: BitArr!(for 69),
data: [MaybeUninit<T::Value>; N],
len: usize,
}
impl<T, const N: usize> FixedPod<T, N>
where
T: Phenotype,
{
const UNINIT: MaybeUninit<T::Value> = MaybeUninit::uninit();
pub fn new() -> Self {
Self {
tags_init: BitArray::ZERO,
data: [Self::UNINIT; N],
len: 0,
}
}
fn len(&self) -> usize {
if let Some(index) = self.tags_init[..32].first_one() {
index + 1
} else {
0
}
}
pub fn push(&mut self, elem: T) -> bool {
let len = self.len();
if len == N {
return false;
}
let (tag, data) = elem.cleave();
if self.check_init(len) {
self.data[len].write(data);
self.set_tag(len, tag);
self.set_init(len);
todo!()
} else {
todo!()
}
}
pub fn force_push(&mut self, elem: T) {
todo!()
}
fn check_init(&self, index: usize) -> bool {
self.tags_init[index]
}
fn set_init(&mut self, index: usize) {
self.tags_init.set(index, true);
}
fn get_tag(&self, index: usize) -> usize {
self.tags_init[N + index * T::BITS..N + (index + 1) * T::BITS].load()
}
fn set_tag(&mut self, index: usize, tag: usize) {
self.tags_init[N + index * T::BITS..N + (index + 1) * T::BITS].store(tag);
}
}
impl<T, const N: usize> Default for FixedPod<T, N>
where
T: Phenotype,
{
fn default() -> Self {
Self::new()
}
}