pub struct FoodDeliverySystem<T: PrimInt + Unsigned> { /* private fields */ }
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

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);

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

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.