Struct xor_distance_exercise::xor_distance::XorDistance
source · Implementations
sourceimpl<T: PrimInt + Unsigned> XorDistance<T>
impl<T: PrimInt + Unsigned> XorDistance<T>
pub fn new(points: Vec<T>) -> Self
sourcepub fn closest(&self, x: T, count: usize) -> Vec<T>
pub fn closest(&self, x: T, count: usize) -> Vec<T>
Return up to requested count of closest points to the provided x
, ordered from the closest
to the n-th closest, where n
is the count.
The returned closest points count my be lower than the specified count and equal to all
points count only in the case that: count > points.len()
.
Examples
extern crate xor_distance_exercise;
use xor_distance_exercise::xor_distance::XorDistance;
let xor_distance: XorDistance<u64> = XorDistance::new(vec![
0, 1, 2, 4, 6, 8, 12, 18, 19, 20, 21, 22, 406, 407, 408, 409, 410, 444, 445,
]);
let x = 200;
let count = 10;
let closest_points = xor_distance.closest(x, count);
sourcepub fn reverse_closest(&self, closest_points: &[T]) -> Option<T>
pub fn reverse_closest(&self, closest_points: &[T]) -> Option<T>
Return a Some(x)
such that self.closest(x)
equals closest_points and return None in case
such a x
does not exists.
Examples
extern crate xor_distance_exercise;
use xor_distance_exercise::xor_distance::XorDistance;
let xor_distance: XorDistance<u64> = XorDistance::new(vec![
0, 1, 2, 4, 6, 8, 12, 18, 19, 20, 21, 22, 406, 407, 408, 409, 410, 444, 445,
]);
let x = 200;
let count = 10;
// Get closest points and reversed guess of `x`
let closest_points = xor_distance.closest(x, count);
let x_guess = xor_distance.reverse_closest(&closest_points).unwrap();
// Check that both `x` and `guess_x` produce the same result.
assert_eq!(closest_points, xor_distance.closest(x_guess, count));
pub fn form_inequalities(&self, closest_points: &[T]) -> Vec<(T, T)>
Auto Trait Implementations
impl<T> RefUnwindSafe for XorDistance<T>where
T: RefUnwindSafe,
impl<T> Send for XorDistance<T>where
T: Send,
impl<T> Sync for XorDistance<T>where
T: Sync,
impl<T> Unpin for XorDistance<T>where
T: Unpin,
impl<T> UnwindSafe for XorDistance<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more