RangeSearcher

Struct RangeSearcher 

Source
pub struct RangeSearcher<'a, T: CodeInt> { /* private fields */ }
Expand description

Range searcher created by Index::range_searcher().

Implementations§

Source§

impl<'a, T> RangeSearcher<'a, T>
where T: CodeInt,

Source

pub fn run(&mut self, qcode: T, radius: usize) -> &[u32]

Searches neighbor codes whose Hamming distances to a query code are within a query radius.

§Arguments
  • qcode: Binary code of the query.
  • radius: Threshold to be searched.
§Returns

A slice of ids of codes whose Hamming distances to qcode are within radius. The ids are sorted. Note that the values of the slice will be updated in the next RangeSearcher::run().

§Examples
use mih_rs::Index;

let codes: Vec<u64> = vec![
    0b1111111111111111111111011111111111111111111111111011101111111111, // #zeros = 3
    0b1111111111111111111111111111111101111111111011111111111111111111, // #zeros = 2
    0b1111111011011101111111111111111101111111111111111111111111111111, // #zeros = 4
    0b1111111111111101111111111111111111111000111111111110001111111110, // #zeros = 8
    0b1101111111111111111111111111111111111111111111111111111111111111, // #zeros = 1
    0b1111111111111111101111111011111111111111111101001110111111111111, // #zeros = 6
    0b1111111111111111111111111111111111101111111111111111011111111111, // #zeros = 2
    0b1110110101011011011111111111111101111111111111111000011111111111, // #zeros = 11
];

let index = Index::new(codes).unwrap();
let mut searcher = index.range_searcher();

let qcode: u64 = 0b1111111111111111111111111111111111111111111111111111111111111111; // #zeros = 0
let answers = searcher.run(qcode, 2);
assert_eq!(answers, vec![1, 4, 6]);

Auto Trait Implementations§

§

impl<'a, T> Freeze for RangeSearcher<'a, T>

§

impl<'a, T> RefUnwindSafe for RangeSearcher<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for RangeSearcher<'a, T>
where T: Sync,

§

impl<'a, T> Sync for RangeSearcher<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for RangeSearcher<'a, T>

§

impl<'a, T> UnwindSafe for RangeSearcher<'a, T>
where T: RefUnwindSafe,

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.