Expand description
Food delivery system of local food from from local farms.
Examples
extern crate xor_distance_exercise;
use xor_distance_exercise::delivery_system::FoodDeliverySystem;
let delivery_system: FoodDeliverySystem<u64> = FoodDeliverySystem::new(vec![
0, 1, 2, 4, 6, 8, 12, 18, 19, 20, 21, 22, 406, 407, 408, 409, 410, 444, 445,
]);
let position = 200;
let count = 10;
// Get closest farms and reversed guess of possible customer's `position`.
let closest_farms = delivery_system.closest_farms(position, count);
let position_guess = delivery_system.reverse_closest_farms(&closest_farms).unwrap();
Implementations
sourceimpl<T: PrimInt + Unsigned> FoodDeliverySystem<T>
impl<T: PrimInt + Unsigned> FoodDeliverySystem<T>
pub fn new(points: Vec<T>) -> Self
sourcepub fn closest_farms(&self, position: T, count: usize) -> Vec<T>
pub fn closest_farms(&self, position: T, count: usize) -> Vec<T>
Return specified count of closest farms to the provided position
.
The closest farms are ordered from the closest to the n-th closest, where n
is the count.
Examples
extern crate xor_distance_exercise;
use xor_distance_exercise::delivery_system::FoodDeliverySystem;
let delivery_system: FoodDeliverySystem<u64> = FoodDeliverySystem::new(vec![
0, 1, 2, 4, 6, 8, 12, 18, 19, 20, 21, 22, 406, 407, 408, 409, 410, 444, 445,
]);
let position = 10;
let count = 10;
let closest_farms = delivery_system.closest_farms(position, count);
sourcepub fn reverse_closest_farms(&self, closest_farms: &[T]) -> Option<T>
pub fn reverse_closest_farms(&self, closest_farms: &[T]) -> Option<T>
Return a Some(position)
such that self.closest(position)
equals closest_farms and return
None in case such a position
does not exists.
Examples
extern crate xor_distance_exercise;
use xor_distance_exercise::delivery_system::FoodDeliverySystem;
let delivery_system: FoodDeliverySystem<u64> = FoodDeliverySystem::new(vec![
0, 1, 2, 4, 6, 8, 12, 18, 19, 20, 21, 22, 406, 407, 408, 409, 410, 444, 445,
]);
let position = 200;
let count = 10;
// Get closest farms and reversed guess of possible customer's `position`.
let closest_farms = delivery_system.closest_farms(position, count);
let position_guess = delivery_system.reverse_closest_farms(&closest_farms).unwrap();
// Check that both `position` and `position_guess` produce the same result.
assert_eq!(closest_farms, delivery_system.closest_farms(position_guess, count));
Auto Trait Implementations
impl<T> RefUnwindSafe for FoodDeliverySystem<T>where
T: RefUnwindSafe,
impl<T> Send for FoodDeliverySystem<T>where
T: Send,
impl<T> Sync for FoodDeliverySystem<T>where
T: Sync,
impl<T> Unpin for FoodDeliverySystem<T>where
T: Unpin,
impl<T> UnwindSafe for FoodDeliverySystem<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