use crate::shared::time_manager::WrappedTime;
use crate::utils::sequence_buffer::SequenceBuffer;
use crate::utils::wrapping_id;
use crate::utils::wrapping_id::wrapping_id;
wrapping_id!(PingId);
const PING_BUFFER_SIZE: usize = 32;
pub struct PingStore {
latest_ping_id: PingId,
buffer: SequenceBuffer<PingId, WrappedTime, PING_BUFFER_SIZE>,
}
impl Default for PingStore {
fn default() -> Self {
Self::new()
}
}
impl PingStore {
pub fn new() -> Self {
PingStore {
latest_ping_id: PingId(0),
buffer: SequenceBuffer::new(),
}
}
pub fn push_new(&mut self, now: WrappedTime) -> PingId {
let ping_id = self.latest_ping_id;
self.latest_ping_id += 1;
self.buffer.push(&ping_id, now);
ping_id
}
pub fn remove(&mut self, ping_id: PingId) -> Option<WrappedTime> {
self.buffer.remove(&ping_id)
}
}