use super::*;
#[derive(Debug)]
pub(crate) struct KeyEntry {
pub(crate) state: AtomicU64,
pub(crate) last_seen_ns: AtomicU64,
}
#[derive(Debug)]
pub(crate) struct ShardSlot<K> {
pub(crate) hash: u64,
pub(crate) key: K,
pub(crate) entry: KeyEntry,
}
#[derive(Debug)]
pub(crate) struct ShardMap<K> {
pub(crate) ctrl: Vec<u8>,
pub(crate) slots: Vec<Option<ShardSlot<K>>>,
pub(crate) len: usize,
pub(crate) tombstones: usize,
}
#[repr(align(128))]
#[derive(Debug)]
pub(crate) struct ReaderSlot {
pub(crate) readers: AtomicU32,
}
pub(crate) struct ShardRwLock<T> {
pub(crate) writer_flag: AtomicU32,
pub(crate) data: UnsafeCell<T>,
}
pub(crate) struct ShardReadGuard<'a, T> {
pub(crate) slot: &'a ReaderSlot,
pub(crate) data: *const T,
}
pub(crate) struct ShardWriteGuard<'a, T> {
pub(crate) lock: &'a ShardRwLock<T>,
}
#[repr(align(128))]
#[derive(Debug)]
pub(crate) struct KeyedShard<K> {
pub(crate) map: ShardRwLock<ShardMap<K>>,
}
#[derive(Debug)]
pub struct KeyedRateLimiter<K> {
pub(crate) policy: RateLimitPolicy,
pub(crate) clock: MonotonicClock,
pub(crate) hasher: FastBuildHasher,
pub(crate) max_entries: usize,
pub(crate) per_shard_capacity: usize,
pub(crate) reader_slots: Box<[ReaderSlot]>,
pub(crate) shards: Box<[KeyedShard<K>]>,
}