Struct gardiz::map::Map

source ·
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,

source

pub fn new() -> Self

Creates a new empty coordinate map.

source

pub fn is_empty(&self) -> bool

Returns whether the map is empty.

source

pub fn len(&self) -> usize

Returns the length of the map, i.e. how many Vec2 (keys) are stored in this map.

source

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.

source

pub fn contains<Q>(&self, point: Vec2<&Q>) -> boolwhere K: Borrow<Q>, Q: Ord,

Tests if the map contains the given point.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn rows(&self) -> Rows<'_, K, V>

Returns an iterator over all entries, by running through the “rows” of the map, (with the first entries having the lowest keys), i.e. all X are yielded before going to the next Y.

source

pub fn columns(&self) -> Columns<'_, K, V>

Returns an iterator over all entries, by running through the “columns” of the map, (with the first entries having the lowest keys), i.e. all Y are yielded before going to the next X.

Trait Implementations§

source§

impl<K, V: Clone> Clone for Map<K, V>where K: Ord + Clone,

source§

fn clone(&self) -> Map<K, V>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K, V: Debug> Debug for Map<K, V>where K: Ord + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K, V> Default for Map<K, V>where K: Ord,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

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

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<K, V> FromIterator<(Vec2<K>, V)> for Map<K, V>where K: Ord + Clone, V: Clone,

source§

fn from_iter<I>(iter: I) -> Selfwhere I: IntoIterator<Item = (Vec2<K>, V)>,

Creates a value from an iterator. Read more
source§

impl<K, V> PartialEq<Map<K, V>> for Map<K, V>where K: Ord, V: PartialEq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K, V> Serialize for Map<K, V>where K: Serialize + Ord, V: Serialize,

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<K, V> Eq for Map<K, V>where K: Ord, V: Eq,

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for Map<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

§

impl<K, V> Send for Map<K, V>where K: Send, V: Send,

§

impl<K, V> Sync for Map<K, V>where K: Sync, V: Sync,

§

impl<K, V> Unpin for Map<K, V>

§

impl<K, V> UnwindSafe for Map<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,