pub trait SetProvider<Key, Value>: AsyncFriendly{
type S: Set<Value> + AsyncFriendly;
// Required methods
fn get(&self, key: &Key) -> ANNResult<Option<Cow<'_, Self::S>>>;
fn count(&self) -> ANNResult<usize>;
fn exists(&self, key: &Key) -> ANNResult<bool>;
fn insert(&mut self, key: &Key, value: &Value) -> ANNResult<bool>;
fn insert_values(&mut self, key: &Key, values: &[Value]) -> ANNResult<bool>;
fn delete(&mut self, key: &Key) -> ANNResult<bool>;
fn delete_from_set(&mut self, key: &Key, value: &Value) -> ANNResult<bool>;
fn clear(&mut self) -> ANNResult<()>;
}Expand description
Provider for sets that may live in memory or in a storage layer.
A SetProvider owns or manages many sets, addressed by a key,
for example vector identifiers to label sets. Each implementation
chooses a concrete set type that fits its backend and usage.
Type parameters:
Keyis the lookup key for an individual set, for example a vector idValueis the element type stored inside each set
Required Associated Types§
Sourcetype S: Set<Value> + AsyncFriendly
type S: Set<Value> + AsyncFriendly
Concrete set type managed by this provider.
Required Methods§
Sourcefn get(&self, key: &Key) -> ANNResult<Option<Cow<'_, Self::S>>>
fn get(&self, key: &Key) -> ANNResult<Option<Cow<'_, Self::S>>>
Get the set for key.
Implementations may borrow internally and return Cow::Borrowed,
or materialize an owned set and return Cow::Owned.
Returns:
Ok(Some(Set)) of the key if the key exists
Ok(None) if the key doesn’t exist
ANNError if there was an error, say in the underlying store.
Sourcefn count(&self) -> ANNResult<usize>
fn count(&self) -> ANNResult<usize>
Number of keys managed by this provider. Returns ANNError if there was an underlying error while retrieving the result (for instance, in the backing store)
Sourcefn exists(&self, key: &Key) -> ANNResult<bool>
fn exists(&self, key: &Key) -> ANNResult<bool>
Check if a key exists. Returns true if the key exists, false otherwise, and ANNError if an error was encountered while processing the operation.
Sourcefn insert(&mut self, key: &Key, value: &Value) -> ANNResult<bool>
fn insert(&mut self, key: &Key, value: &Value) -> ANNResult<bool>
Insert value into the set for key.
If the key is missing, create an empty set first, then insert. Returns true if the value was inserted, false if the value already exists, has nothing to do with the key. This is because we always expect multiple insert calls with the same key, so it is not important whether the key exists before insert or not.
Returns ANNError if there was an underlying error in the operation.
Sourcefn insert_values(&mut self, key: &Key, values: &[Value]) -> ANNResult<bool>
fn insert_values(&mut self, key: &Key, values: &[Value]) -> ANNResult<bool>
Insert values for a key If the key is missing, it will create a new entry. Returns true if the all the values were inserted, false if any of them already exist.
Returns ANNError if there is an underlying failure. Currently, there is no way to indicate the insertion status of an individual value.
Sourcefn delete(&mut self, key: &Key) -> ANNResult<bool>
fn delete(&mut self, key: &Key) -> ANNResult<bool>
Delete the entire set for key.
Returns true if the key is present. false, otherwise, and ANNError if an error was encountered during the operation.