use std::{future::Future, num::NonZeroUsize};
use super::{StorageReadProvider, StorageWriteProvider};
use diskann_vector::distance::Metric;
use super::get_mem_index_data_file;
use crate::model::graph::provider::async_::PrefetchCacheLineLevel;
pub trait SaveWith<T> {
type Ok: Send;
type Error: std::error::Error + Send;
fn save_with<P>(
&self,
provider: &P,
auxiliary: &T,
) -> impl Future<Output = Result<Self::Ok, Self::Error>> + Send
where
P: StorageWriteProvider;
}
pub trait LoadWith<T>: Sized {
type Error: std::error::Error + Send;
fn load_with<P>(
provider: &P,
auxiliary: &T,
) -> impl Future<Output = Result<Self, Self::Error>> + Send
where
P: StorageReadProvider;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AsyncIndexMetadata {
prefix: String,
}
impl AsyncIndexMetadata {
pub fn new<T>(pathlike: T) -> Self
where
String: From<T>,
{
Self {
prefix: pathlike.into(),
}
}
pub fn prefix(&self) -> &str {
&self.prefix
}
pub fn data_path(&self) -> String {
get_mem_index_data_file(&self.prefix)
}
pub fn additional_points_id_path(&self) -> String {
format!("{}.additional_points_id", self.prefix)
}
}
#[derive(Debug, Clone)]
pub struct DiskGraphOnly {
prefix: String,
}
impl DiskGraphOnly {
pub fn new<T>(pathlike: T) -> Self
where
String: From<T>,
{
Self {
prefix: pathlike.into(),
}
}
pub fn prefix(&self) -> &str {
&self.prefix
}
}
pub struct AsyncQuantLoadContext {
pub metadata: AsyncIndexMetadata,
pub num_frozen_points: NonZeroUsize,
pub metric: Metric,
pub prefetch_lookahead: Option<usize>,
pub is_disk_index: bool,
pub prefetch_cache_line_level: Option<PrefetchCacheLineLevel>,
}