Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UpcastIndex trait #43

Merged
merged 3 commits into from
Jul 23, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,22 @@ impl TryFromInnerPtr for IndexImpl {
}
}

/// If you need to store several different types of indexes in one collection.
/// You can cast all indexes to one type of IndexImpl.
/// # Examples
///
/// ```
/// use faiss::{index::{IndexImpl, UpcastIndex}, FlatIndex, index_factory, MetricType};
/// let f1 = FlatIndex::new_l2(128).unwrap();
/// let f2 = index_factory(128, "Flat", MetricType::L2).unwrap();
/// let v: Vec<IndexImpl> = vec![
/// f1.upcast(),
/// f2,
/// ];
/// ```
ava57r marked this conversation as resolved.
Show resolved Hide resolved
///
pub trait UpcastIndex: NativeIndex {
Enet4 marked this conversation as resolved.
Show resolved Hide resolved
/// Converting an index to the base type of `IndexImpl`
ava57r marked this conversation as resolved.
Show resolved Hide resolved
fn upcast(self) -> IndexImpl;
}

Expand Down