Skip to main content

SetProvider

Trait SetProvider 

Source
pub trait SetProvider<Key, Value>: AsyncFriendly
where Key: Clone + Eq + Hash, Value: Clone + Eq + Hash,
{ 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:

  • Key is the lookup key for an individual set, for example a vector id
  • Value is the element type stored inside each set

Required Associated Types§

Source

type S: Set<Value> + AsyncFriendly

Concrete set type managed by this provider.

Required Methods§

Source

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.

Source

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)

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn delete_from_set(&mut self, key: &Key, value: &Value) -> ANNResult<bool>

Remove value from the set for key.

Returns true if the value was present and removed. false otherwise. ANNError is returned if the operation fails.

Source

fn clear(&mut self) -> ANNResult<()>

Clear all the keys and values in the set.

Returns error if the operation failedd

Implementors§