Struct SearchIndexHashMap

Source
pub struct SearchIndexHashMap<P, V> { /* private fields */ }
Expand description

SearchIndexHashMap is a index backed by a HashMap that can match Exact queries.

§Example

use attribute_search_engine::{SearchIndex, SearchIndexHashMap};
use std::collections::HashSet;
use attribute_search_engine::Query;

let mut index_city = SearchIndexHashMap::<usize, String>::new();
index_city.insert(0, "Berlin".into());
index_city.insert(1, "New York".into());
index_city.insert(2, "Madrid".into());

let result = index_city.search(&Query::Exact("<unused>".into(), "New York".into()));
assert_eq!(result, Ok(HashSet::from_iter(vec![1])));

Implementations§

Source§

impl<P, V> SearchIndexHashMap<P, V>
where P: Eq + Hash + Clone + 'static, V: Eq + Hash + FromStr + 'static,

Source

pub fn new() -> Self

Creates a new SearchIndexHashMap.

§Example
use attribute_search_engine::SearchIndexHashMap;

let index = SearchIndexHashMap::<usize, String>::new();
Source

pub fn insert(&mut self, primary_id: P, attribute_value: V)

Insert a new entry in the index.

§Example
use attribute_search_engine::SearchIndexHashMap;

let mut index = SearchIndexHashMap::<usize, String>::new();

// You insert an entry by giving a row / primary id and an attribute value:
index.insert(123, "A".into());
// The same row / primary id can have multiple attributes assigned:
index.insert(123, "B".into());
// Add as much entries as you want for as many rows you want:
index.insert(124, "C".into());

Trait Implementations§

Source§

impl<P, V> Default for SearchIndexHashMap<P, V>
where P: Eq + Hash + Clone + 'static, V: Eq + Hash + FromStr + 'static,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<P: Clone, V: Eq + Hash + FromStr> SearchIndex<P> for SearchIndexHashMap<P, V>

Source§

fn search(&self, query: &Query) -> Result<HashSet<P>>

Perform a search on an index. Read more
Source§

fn supported_queries(&self) -> SupportedQueries

Returns which queries are directly supported by an index. Read more

Auto Trait Implementations§

§

impl<P, V> Freeze for SearchIndexHashMap<P, V>

§

impl<P, V> RefUnwindSafe for SearchIndexHashMap<P, V>

§

impl<P, V> Send for SearchIndexHashMap<P, V>
where V: Send, P: Send,

§

impl<P, V> Sync for SearchIndexHashMap<P, V>
where V: Sync, P: Sync,

§

impl<P, V> Unpin for SearchIndexHashMap<P, V>
where V: Unpin, P: Unpin,

§

impl<P, V> UnwindSafe for SearchIndexHashMap<P, V>
where V: UnwindSafe, P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.