use alloc::{collections::BTreeMap, string::String};
use crate::codec::CompressedVector;
use crate::corpus::entry_meta_value::EntryMetaValue;
use crate::types::{Timestamp, VectorId};
#[derive(Clone, Debug)]
pub struct VectorEntry {
vector_id: VectorId,
compressed: CompressedVector,
declared_dimension: u32,
inserted_at: Timestamp,
metadata: BTreeMap<String, EntryMetaValue>,
}
impl VectorEntry {
#[must_use]
pub const fn new(
vector_id: VectorId,
compressed: CompressedVector,
declared_dimension: u32,
inserted_at: Timestamp,
metadata: BTreeMap<String, EntryMetaValue>,
) -> Self {
Self {
vector_id,
compressed,
declared_dimension,
inserted_at,
metadata,
}
}
#[must_use]
pub const fn vector_id(&self) -> &VectorId {
&self.vector_id
}
#[must_use]
pub const fn compressed(&self) -> &CompressedVector {
&self.compressed
}
#[must_use]
pub const fn inserted_at(&self) -> Timestamp {
self.inserted_at
}
#[must_use]
pub const fn metadata(&self) -> &BTreeMap<String, EntryMetaValue> {
&self.metadata
}
pub fn metadata_mut(&mut self) -> &mut BTreeMap<String, EntryMetaValue> {
&mut self.metadata
}
#[must_use]
pub const fn config_hash(&self) -> &crate::types::ConfigHash {
self.compressed.config_hash()
}
#[must_use]
pub const fn dimension(&self) -> u32 {
self.declared_dimension
}
#[must_use]
pub fn has_residual(&self) -> bool {
self.compressed.has_residual()
}
}
impl PartialEq for VectorEntry {
fn eq(&self, other: &Self) -> bool {
self.vector_id == other.vector_id
}
}
impl Eq for VectorEntry {}
impl core::hash::Hash for VectorEntry {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.vector_id.hash(state);
}
}