1use std::any::TypeId;
2use std::fmt::{Debug, Display};
3use std::hash::Hash;
45/// The type of index
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[non_exhaustive]
8pub enum IndexType {
9/// A hash index that supports lookup by value.
10Hash,
11/// A range index that supports range search
12Range,
13/// A full text index
14FullText,
15}
1617impl Display for IndexType {
18fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19match self {
20 IndexType::Hash => write!(f, "hash"),
21 IndexType::Range => write!(f, "range"),
22 IndexType::FullText => write!(f, "full text"),
23 }
24 }
25}
2627/// An Index is a fast lookup mechanism for graph elements.
28///
29/// Indexes allow for efficient querying of graph elements based on different criteria.
30/// Each index has a type and can be identified by an ordinal within its type.
31pub trait Index
32where
33Self: Sized + Copy + Eq + Hash + Debug,
34{
35/// Returns the TypeId of the element being indexed.
36 ///
37 /// Supported types are graph dependent, but all graph implementations support
38 /// basic Rust types and strings.
39fn ty(&self) -> TypeId;
4041/// Returns the ordinal number of this index.
42 ///
43 /// The ordinal uniquely identifies an index within its index type.
44fn ordinal(&self) -> usize;
4546/// Returns the type of this index (Hash, Range, or FullText).
47fn index_type(&self) -> IndexType;
48}
4950impl Index for () {
51fn ty(&self) -> TypeId {
52unimplemented!("index not implemented")
53 }
5455fn ordinal(&self) -> usize {
56unimplemented!("index not implemented")
57 }
5859fn index_type(&self) -> IndexType {
60unimplemented!("index not implemented")
61 }
62}