use super::{IndexError, IndexStatistics, IndexType, SearchQuery, SearchResult};
use crate::storage::Value;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[async_trait]
#[allow(dead_code)] pub trait Index: Send + Sync {
async fn insert(&mut self, key: &[u8], value: &[u8]) -> Result<(), IndexError>;
async fn search(&self, query: &SearchQuery) -> Result<Vec<SearchResult>, IndexError>;
async fn delete(&mut self, key: &[u8]) -> Result<bool, IndexError>;
async fn contains(&self, key: &[u8]) -> Result<bool, IndexError>;
fn size(&self) -> usize;
fn stats(&self) -> &IndexStatistics;
fn name(&self) -> &str;
fn index_type(&self) -> &IndexType;
async fn maintenance(&mut self) -> Result<(), IndexError>;
async fn flush(&mut self) -> Result<(), IndexError>;
fn memory_usage(&self) -> usize;
fn is_ready(&self) -> bool;
async fn shutdown(&mut self) -> Result<(), IndexError>;
fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
}
#[async_trait]
#[allow(dead_code)] pub trait BatchIndex: Index {
async fn batch_insert(&mut self, entries: Vec<(Vec<u8>, Vec<u8>)>) -> Result<(), IndexError>;
async fn batch_delete(&mut self, keys: Vec<Vec<u8>>) -> Result<usize, IndexError>;
async fn batch_search(
&self,
queries: Vec<SearchQuery>,
) -> Result<Vec<Vec<SearchResult>>, IndexError>;
}
#[async_trait]
#[allow(dead_code)] pub trait GraphIndex: Index {
async fn add_edge(
&mut self,
source: &str,
target: &str,
properties: Option<HashMap<String, Value>>,
) -> Result<(), IndexError>;
async fn remove_edge(&mut self, source: &str, target: &str) -> Result<bool, IndexError>;
async fn get_neighbors(
&self,
node: &str,
direction: super::Direction,
) -> Result<Vec<String>, IndexError>;
async fn has_path(
&self,
source: &str,
target: &str,
max_hops: Option<usize>,
) -> Result<bool, IndexError>;
async fn shortest_path(
&self,
source: &str,
target: &str,
) -> Result<Option<Vec<String>>, IndexError>;
async fn degree(&self, node: &str) -> Result<usize, IndexError>;
}
#[async_trait]
#[allow(dead_code)] pub trait PartitionedIndex: Index {
fn get_partition(&self, key: &[u8]) -> String;
fn get_partitions(&self) -> Vec<String>;
fn partition_stats(&self, partition_id: &str) -> Option<IndexStatistics>;
async fn rebalance(&mut self) -> Result<(), IndexError>;
}
#[async_trait]
#[allow(dead_code)] pub trait IndexLifecycle {
async fn create(&mut self) -> Result<(), IndexError>;
async fn load(&mut self) -> Result<(), IndexError>;
async fn save(&self) -> Result<(), IndexError>;
async fn drop(&mut self) -> Result<(), IndexError>;
fn metadata(&self) -> IndexMetadata;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IndexMetadata {
pub name: String,
pub index_type: IndexType,
pub created_at: chrono::DateTime<chrono::Utc>,
pub modified_at: chrono::DateTime<chrono::Utc>,
pub version: String,
pub properties: HashMap<String, Value>,
}