use std::sync::atomic::{AtomicU64, Ordering};
pub(super) const MAGIC: [u8; 4] = *b"NDVS";
pub(super) const FORMAT_VERSION: u16 = 1;
pub(super) const DTYPE_F32: u8 = 0;
pub(super) const HEADER_SIZE: usize = 32;
#[inline]
pub(super) const fn vec_pad(vec_bytes: usize) -> usize {
(8 - (vec_bytes % 8)) % 8
}
pub(super) const FOOTER_SIZE: usize = 46;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
#[non_exhaustive]
pub enum VectorSegmentCodec {
None = 0,
}
impl VectorSegmentCodec {
pub(super) fn from_u8(v: u8) -> std::io::Result<Self> {
match v {
0 => Ok(Self::None),
other => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!("unknown VectorSegmentCodec byte {other}"),
)),
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct VectorSegmentDropPolicy {
dontneed_on_drop: bool,
}
impl VectorSegmentDropPolicy {
pub const fn new(dontneed_on_drop: bool) -> Self {
Self { dontneed_on_drop }
}
pub const fn keep_resident() -> Self {
Self {
dontneed_on_drop: false,
}
}
pub const fn dontneed_on_drop(self) -> bool {
self.dontneed_on_drop
}
}
impl Default for VectorSegmentDropPolicy {
fn default() -> Self {
Self {
dontneed_on_drop: true,
}
}
}
pub mod observability {
use super::{AtomicU64, Ordering};
pub(crate) static DONTNEED_COUNT: AtomicU64 = AtomicU64::new(0);
pub(crate) static RANDOM_COUNT: AtomicU64 = AtomicU64::new(0);
pub fn dontneed_count() -> u64 {
DONTNEED_COUNT.load(Ordering::Relaxed)
}
pub fn random_count() -> u64 {
RANDOM_COUNT.load(Ordering::Relaxed)
}
}