[−][src]Struct hwt::Hwt
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]
F: FnMut(u32) -> u128,
Inserts an item ID to the Hwt
.
F
: A function which should give thefeature
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]
F: FnMut(u32) -> u128,
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]
&'a self,
feature: u128,
lookup: &'a F
) -> impl Iterator<Item = u32> + 'a where
F: Fn(u32) -> u128,
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_radius<'a, F: 'a>(
&'a self,
radius: u32,
feature: u128,
lookup: &'a F
) -> impl Iterator<Item = u32> + 'a where
F: Fn(u32) -> u128,
[src]
&'a self,
radius: u32,
feature: u128,
lookup: &'a F
) -> impl Iterator<Item = u32> + 'a where
F: Fn(u32) -> u128,
Find all neighbors within a given radius.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,