use std::sync::Arc;
use smallvec::SmallVec;
use selene_core::{DbString, HnswIndexConfig, IvfIndexConfig};
use crate::composite_typed_index::CompositeTypedIndex;
use crate::text_index::{TextIndex, TextIndexMemoryUsage, TextIndexStats};
use crate::typed_index::{TypedIndex, TypedIndexKind};
use crate::vector_index::{VectorIndex, VectorIndexKind, VectorIndexMemoryUsage};
#[derive(Clone, Debug)]
pub struct PropertyIndexEntry {
pub index: Arc<TypedIndex>,
pub name: Option<DbString>,
}
impl PropertyIndexEntry {
#[must_use]
pub fn new(index: TypedIndex, name: Option<DbString>) -> Self {
Self {
index: Arc::new(index),
name,
}
}
#[must_use]
pub fn kind(&self) -> TypedIndexKind {
self.index.kind()
}
}
#[derive(Clone, Debug)]
pub struct CompositePropertyIndexEntry {
pub index: Arc<CompositeTypedIndex>,
pub declared_properties: SmallVec<[DbString; 4]>,
pub name: Option<DbString>,
}
impl CompositePropertyIndexEntry {
#[must_use]
pub fn new(
index: CompositeTypedIndex,
declared_properties: SmallVec<[DbString; 4]>,
name: Option<DbString>,
) -> Self {
Self {
index: Arc::new(index),
declared_properties,
name,
}
}
#[must_use]
pub fn kinds(&self) -> SmallVec<[TypedIndexKind; 4]> {
self.index.kinds().iter().copied().collect()
}
}
#[derive(Clone, Debug)]
pub struct VectorIndexEntry {
pub index: Arc<VectorIndex>,
pub name: Option<DbString>,
}
impl VectorIndexEntry {
#[must_use]
pub fn new(index: VectorIndex, name: Option<DbString>) -> Self {
Self {
index: Arc::new(index),
name,
}
}
#[must_use]
pub fn kind(&self) -> VectorIndexKind {
self.index.kind()
}
#[must_use]
pub fn dimension(&self) -> u32 {
self.index.dimension()
}
#[must_use]
pub fn hnsw_config(&self) -> Option<HnswIndexConfig> {
self.index.hnsw_config()
}
#[must_use]
pub fn ivf_config(&self) -> Option<IvfIndexConfig> {
self.index.ivf_config()
}
#[must_use]
pub fn memory_usage(&self) -> VectorIndexMemoryUsage {
self.index.memory_usage()
}
}
#[derive(Clone, Debug)]
pub struct TextIndexEntry {
pub index: Arc<TextIndex>,
pub name: Option<DbString>,
}
impl TextIndexEntry {
#[must_use]
pub fn new(index: TextIndex, name: Option<DbString>) -> Self {
Self {
index: Arc::new(index),
name,
}
}
#[must_use]
pub fn stats(&self) -> TextIndexStats {
self.index.stats()
}
#[must_use]
pub fn memory_usage(&self) -> TextIndexMemoryUsage {
self.index.memory_usage()
}
}
pub type CompositePropertyIndexEntryRow = (
DbString,
SmallVec<[DbString; 4]>,
SmallVec<[TypedIndexKind; 4]>,
Option<DbString>,
);
pub type VectorIndexEntryRow = (
DbString,
DbString,
VectorIndexKind,
u32,
Option<HnswIndexConfig>,
Option<IvfIndexConfig>,
Option<DbString>,
);
pub type TextIndexEntryRow = (
DbString,
DbString,
TextIndexStats,
TextIndexMemoryUsage,
Option<DbString>,
);