hnsw_rs/
filter.rs

1//! defines a trait for filtering requests.  
2//! See examples in tests/filtertest.rs
3
4use crate::prelude::DataId;
5
6/// Only queries returning true are taken into account along the search
7pub trait FilterT {
8    fn hnsw_filter(&self, id: &DataId) -> bool;
9}
10
11impl FilterT for Vec<usize> {
12    fn hnsw_filter(&self, id: &DataId) -> bool {
13        self.binary_search(id).is_ok()
14    }
15}
16
17impl<F> FilterT for F
18where
19    F: Fn(&DataId) -> bool,
20{
21    fn hnsw_filter(&self, id: &DataId) -> bool {
22        self(id)
23    }
24}