use std::collections::BTreeMap;
use hashbrown::HashTable;
use super::EntryArena;
use super::Record;
use super::Sequence;
use super::SlotId;
#[derive(Clone, Debug)]
pub(crate) struct InternalState<K, O, V> {
pub(crate) arena: EntryArena<Record<K, O, V>>,
pub(crate) primary: HashTable<SlotId>,
pub(crate) ordered: BTreeMap<(O, Sequence), SlotId>,
pub(crate) next_sequence: u64,
}
impl<K, O, V> InternalState<K, O, V> {
#[must_use]
#[inline]
pub(crate) const fn new() -> Self {
Self {
arena: EntryArena::new(),
primary: HashTable::new(),
ordered: BTreeMap::new(),
next_sequence: 0,
}
}
#[must_use]
#[inline]
pub(crate) fn with_capacity(capacity: usize) -> Self {
Self {
arena: EntryArena::with_capacity(capacity),
primary: HashTable::with_capacity(capacity),
ordered: BTreeMap::new(),
next_sequence: 0,
}
}
#[must_use]
#[inline]
pub(crate) fn allocate_sequence(&mut self) -> Sequence {
let sequence = Sequence(self.next_sequence);
self.next_sequence = self
.next_sequence
.checked_add(1)
.expect("ordered index attachment sequences exhausted");
sequence
}
}