[][src]Struct hwt::Hwt

pub struct Hwt { /* fields omitted */ }

Methods

impl Hwt[src]

pub fn new() -> Self[src]

Makes an empty Hwt.

let hwt = Hwt::new();
assert!(hwt.is_empty());

pub fn len(&self) -> usize[src]

Gets the number of entries in the Hwt.

let mut hwt = Hwt::new();
hwt.insert(0b101, 0, |_| 0b010);
assert_eq!(hwt.len(), 1);

pub fn is_empty(&self) -> bool[src]

Checks if the Hwt is empty.

let mut hwt = Hwt::new();
assert!(hwt.is_empty());
hwt.insert(0b101, 0, |_| 0b010);
assert!(!hwt.is_empty());

pub fn insert<F>(&mut self, feature: u128, item: u32, lookup: F) where
    F: FnMut(u32) -> u128
[src]

Inserts an item ID to the Hwt.

  • F: A function which should give the feature for the given ID.

The most significant bit must not be set on the item.

Returns Some(t) if item t was replaced by item.

let mut hwt = Hwt::new();
hwt.insert(0b101, 0, |_| 0b010);
hwt.insert(0b010, 1, |_| 0b101);
assert_eq!(hwt.len(), 2);

pub fn get<F>(&mut self, feature: u128, lookup: F) -> Option<u32> where
    F: FnMut(u32) -> u128
[src]

Looks up an item ID from the Hwt.

Returns Some(t) if item t was in the Hwt, otherwise None.

let mut hwt = Hwt::new();
let lookup = |n| match n { 0 => 0b101, 1 => 0b010, _ => panic!() };
hwt.insert(0b101, 0, lookup);
hwt.insert(0b010, 1, lookup);
assert_eq!(hwt.get(0b101, lookup), Some(0));
assert_eq!(hwt.get(0b010, lookup), Some(1));
assert_eq!(hwt.get(0b000, lookup), None);
assert_eq!(hwt.get(0b111, lookup), None);

pub fn nearest<'a, F: 'a>(
    &'a self,
    feature: u128,
    lookup: &'a F
) -> impl Iterator<Item = u32> + 'a where
    F: Fn(u32) -> u128
[src]

Find the nearest neighbors to a feature. This will give the nearest neighbors first and expand outwards. This evaluates lazily, so use Iterator::take() to just take as many as you need.

pub fn search_exact<'a, F: 'a>(
    &'a self,
    radius: u32,
    feature: u128,
    lookup: &'a F
) -> impl Iterator<Item = u32> + 'a where
    F: Fn(u32) -> u128
[src]

Find all neighbors exactly at a given radius.

pub fn search_radius<'a, F: 'a>(
    &'a self,
    radius: u32,
    feature: u128,
    lookup: &'a F
) -> impl Iterator<Item = u32> + 'a where
    F: Fn(u32) -> u128
[src]

Find all neighbors within a given radius.

Trait Implementations

impl Default for Hwt[src]

Auto Trait Implementations

impl Send for Hwt

impl Sync for Hwt

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]