[−][src]Struct xor_distance_exercise::delivery_system::FoodDeliverySystem
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();
Methods
impl<T: PrimInt + Unsigned> FoodDeliverySystem<T>
[src]
pub fn new(points: Vec<T>) -> Self
[src]
pub fn closest_farms(&self, position: T, count: usize) -> Vec<T>
[src]
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);
pub fn reverse_closest_farms(&self, closest_farms: &[T]) -> Option<T>
[src]
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> Send for FoodDeliverySystem<T> where
T: Send,
T: Send,
impl<T> Sync for FoodDeliverySystem<T> where
T: Sync,
T: Sync,
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 = !
🔬 This is a nightly-only experimental API. (
try_from
)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> 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>,
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,