use std::marker;
use crate::depot::queue::round::{self, phase};
pub struct Group<'a, T, const G: usize, const N: usize = 0> {
pub(in crate::depot::queue::round) owner: &'a round::Lanes<T, G, N>,
pub(in crate::depot::queue::round) index: usize,
pub(super) item: marker::PhantomData<fn(T) -> T>,
}
impl<'a, T, const G: usize, const N: usize> Group<'a, T, G, N> {
pub(in crate::depot::queue::round) fn select(
&self,
) -> Option<round::Location<&'a round::Lanes<T, G, N>, phase::Head>> {
let ring = unsafe { self.owner.groups.get_unchecked(self.index) };
let lane = ring.first()?;
let track = unsafe { self.owner.block.tail().get_unchecked(lane.get()) };
let index = unsafe { track.entries.front_key() };
Some(round::Location::new(
self.owner,
round::Position { lane, index },
))
}
pub fn active(&self) -> Option<round::Snapshot<&'a round::Lanes<T, G, N>, round::Turn>> {
let entry = self.select()?;
Some(round::Snapshot::new(entry.owner, entry.position))
}
pub fn next(&self) -> Option<(usize, &'a T)> {
let head = self.select()?;
let lane = head.lane();
let value = round::Location::take_active(unsafe { crate::depot::raw::Proof::new(head) });
Some((lane, value))
}
}