pub struct Map<K, V>where
K: Ord,{ /* private fields */ }
Expand description
Map of coordinates in a plane to arbitrary data. Optimized given the fact
the coordinates/vectors are in the plane. Keys of the map are Vec2<K>
.
Implementations§
source§impl<K, V> Map<K, V>where
K: Ord,
impl<K, V> Map<K, V>where K: Ord,
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the map, i.e. how many Vec2
(keys) are stored
in this map.
sourcepub fn get<Q>(&self, point: Vec2<&Q>) -> Option<&V>where
K: Borrow<Q>,
Q: Ord,
pub fn get<Q>(&self, point: Vec2<&Q>) -> Option<&V>where K: Borrow<Q>, Q: Ord,
Attempts to get the data associated with the given point.
sourcepub fn contains<Q>(&self, point: Vec2<&Q>) -> boolwhere
K: Borrow<Q>,
Q: Ord,
pub fn contains<Q>(&self, point: Vec2<&Q>) -> boolwhere K: Borrow<Q>, Q: Ord,
Tests if the map contains the given point.
sourcepub fn neighbours<Q>(
&self,
point: Vec2<&Q>,
direction: Direction
) -> Neighbours<'_, K, V> ⓘwhere
K: Borrow<Q>,
Q: Ord,
pub fn neighbours<Q>( &self, point: Vec2<&Q>, direction: Direction ) -> Neighbours<'_, K, V> ⓘwhere K: Borrow<Q>, Q: Ord,
Returns an iterator to the neighbours of a given point in a straight line in the given direction. The starting point is NOT included. For every point yielded by the iterator, the associated data is also returned.
sourcepub fn neighbours_incl<Q>(
&self,
point: Vec2<&Q>,
direction: Direction
) -> Neighbours<'_, K, V> ⓘwhere
K: Borrow<Q>,
Q: Ord,
pub fn neighbours_incl<Q>( &self, point: Vec2<&Q>, direction: Direction ) -> Neighbours<'_, K, V> ⓘwhere K: Borrow<Q>, Q: Ord,
Returns an iterator to the neighbours of a given point in a straight line in the given direction. The starting point IS included. For every point yielded by the iterator, the associated data is also returned.
sourcepub fn first_neighbour<Q>(
&self,
point: Vec2<&Q>,
direction: Direction
) -> Option<Vec2<&K>>where
K: Borrow<Q>,
Q: Ord,
pub fn first_neighbour<Q>( &self, point: Vec2<&Q>, direction: Direction ) -> Option<Vec2<&K>>where K: Borrow<Q>, Q: Ord,
Returns the nearest neighbour in a straight line of a given point in the the given direction WITHOUT the associated data.
sourcepub fn first_neighbour_data<Q>(
&self,
point: Vec2<&Q>,
direction: Direction
) -> Option<(Vec2<&K>, &V)>where
K: Borrow<Q>,
Q: Ord,
pub fn first_neighbour_data<Q>( &self, point: Vec2<&Q>, direction: Direction ) -> Option<(Vec2<&K>, &V)>where K: Borrow<Q>, Q: Ord,
Returns the nearest neighbour in a straight line of a given point in the given direction WITH the associated data.
sourcepub fn last_neighbour<Q>(
&self,
point: Vec2<&Q>,
direction: Direction
) -> Option<Vec2<&K>>where
K: Borrow<Q>,
Q: Ord,
pub fn last_neighbour<Q>( &self, point: Vec2<&Q>, direction: Direction ) -> Option<Vec2<&K>>where K: Borrow<Q>, Q: Ord,
Returns the furthest neighbour in a straight line of a given point in the given direction WITHOUT the associated data.
sourcepub fn last_neighbour_data<Q>(
&self,
point: Vec2<&Q>,
direction: Direction
) -> Option<(Vec2<&K>, &V)>where
K: Borrow<Q>,
Q: Ord,
pub fn last_neighbour_data<Q>( &self, point: Vec2<&Q>, direction: Direction ) -> Option<(Vec2<&K>, &V)>where K: Borrow<Q>, Q: Ord,
Returns the furthest neighbour in a straight line of a given point in the given direction WITH the associated data.
sourcepub fn insert(&mut self, point: Vec2<K>, value: V) -> Option<V>where
K: Clone,
V: Clone,
pub fn insert(&mut self, point: Vec2<K>, value: V) -> Option<V>where K: Clone, V: Clone,
Inserts the given point with its associated data. A possible previous value is returned.
sourcepub fn create(&mut self, point: Vec2<K>, value: V) -> boolwhere
K: Clone,
V: Clone,
pub fn create(&mut self, point: Vec2<K>, value: V) -> boolwhere K: Clone, V: Clone,
Creates an entry at the given point with its associated data. Fails if there already is an entry for that point. Returns whether it succeeded.
sourcepub fn update<Q>(&mut self, point: Vec2<&Q>, value: V) -> Result<V, V>where
K: Borrow<Q>,
Q: Ord,
V: Clone,
pub fn update<Q>(&mut self, point: Vec2<&Q>, value: V) -> Result<V, V>where K: Borrow<Q>, Q: Ord, V: Clone,
Updates an existing point’s entry with the given value. The entry must
exist. Returns Ok(old_value)
if successful, but Err(attempted_value)
if failing.
sourcepub fn remove<Q>(&mut self, point: Vec2<&Q>) -> Option<V>where
K: Borrow<Q>,
Q: Ord,
pub fn remove<Q>(&mut self, point: Vec2<&Q>) -> Option<V>where K: Borrow<Q>, Q: Ord,
Removes the given point entry from the from the map. Returns the data associated with the point, if successful.
Trait Implementations§
source§impl<'de, K, V> Deserialize<'de> for Map<K, V>where
K: Deserialize<'de> + Ord + Clone,
V: Deserialize<'de> + Clone,
impl<'de, K, V> Deserialize<'de> for Map<K, V>where K: Deserialize<'de> + Ord + Clone, V: Deserialize<'de> + Clone,
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
source§impl<K, V> Extend<(Vec2<K>, V)> for Map<K, V>where
K: Ord + Clone,
V: Clone,
impl<K, V> Extend<(Vec2<K>, V)> for Map<K, V>where K: Ord + Clone, V: Clone,
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (Vec2<K>, V)>,
fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = (Vec2<K>, V)>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)