diff --git a/CHANGELOG.md b/CHANGELOG.md index 6759753..57f6c60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased - ReleaseDate +### Added + +- Added the `ZosditMap::remove_last_value_at_point()` method similar to the + existing `ZosditMap::get_last_value_at_point()` method. + +### Changed +- Some spelling errors corrected + ## 0.9.0 - 2024-02-11 ### Added diff --git a/README.md b/README.md index b18bd30..941d297 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ off [`BTreeMap`]. Several Discrete Interval Tree data-structures have been implemented, here is a brief summary of each of them and why you might use them: -| Struct|Abreviation|Use-Case| +| Struct|Abbreviation|Use-Case| |-----|------|------| |[`NoditMap`]|Non-Overlapping Discrete Interval Tree Map| General purpose way of associating data with intervals that do not overlap| |[`NoditSet`]|Non-Overlapping Discrete Interval Tree Set| Useful for when you want to store intervals but don't want/need to associate data with each interval| diff --git a/src/gqdit/mod.rs b/src/gqdit/mod.rs index 17062ca..f503da2 100644 --- a/src/gqdit/mod.rs +++ b/src/gqdit/mod.rs @@ -340,8 +340,8 @@ where /// Inserts an interval into the structure assigned to the given /// identifiers. /// - /// How overlapping/touching intervals of the same specificer are - /// stored internally is unspecificed since only the gaps are able to + /// How overlapping/touching intervals of the same specifier are + /// stored internally is unspecified since only the gaps are able to /// be queried and regardless of how they are stored the gaps will be /// the same. /// diff --git a/src/lib.rs b/src/lib.rs index 86b8468..db4c9e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ //! Several Discrete Interval Tree data-structures have been implemented, here //! is a brief summary of each of them and why you might use them: //! -//! | Struct|Abreviation|Use-Case| +//! | Struct|Abbreviation|Use-Case| //! |-----|------|------| //! |[`NoditMap`]|Non-Overlapping Discrete Interval Tree Map| General purpose way of associating data with intervals that do not overlap| //! |[`NoditSet`]|Non-Overlapping Discrete Interval Tree Set| Useful for when you want to store intervals but don't want/need to associate data with each interval| @@ -371,7 +371,7 @@ #![allow(clippy::tabs_in_doc_comments)] #![allow(clippy::needless_return)] -#![cfg_attr(not(test), no_std)] +#![no_std] extern crate alloc; diff --git a/src/nodit/map.rs b/src/nodit/map.rs index 53ec0ca..4ab401c 100644 --- a/src/nodit/map.rs +++ b/src/nodit/map.rs @@ -1515,6 +1515,10 @@ mod serde { #[cfg(test)] mod tests { + extern crate std; + + use std::dbg; + use pretty_assertions::assert_eq; use super::*; diff --git a/src/zosdit/map.rs b/src/zosdit/map.rs index 3c90bc0..f53bdb8 100644 --- a/src/zosdit/map.rs +++ b/src/zosdit/map.rs @@ -189,6 +189,62 @@ where .and_then(|(_, x)| x.last()) } + /// Removes the last value stored in the `SmallVec` for the interval(s) + /// that contain that point. + /// + /// # Examples + /// ``` + /// use nodit::interval::ii; + /// use nodit::ZosditMap; + /// + /// let mut map = ZosditMap::from_slice_strict_back([ + /// (ii(0, 4), -2), + /// (ii(4, 4), -4), + /// (ii(4, 4), -8), + /// (ii(4, 8), -10), + /// ]) + /// .unwrap(); + /// + /// assert_eq!(map.get_last_value_at_point(4), Some(&-10)); + /// assert_eq!(map.remove_last_value_at_point(4), Some(-10)); + /// + /// assert_eq!(map.get_last_value_at_point(4), Some(&-8)); + /// assert_eq!(map.remove_last_value_at_point(4), Some(-8)); + /// + /// assert_eq!(map.get_last_value_at_point(4), Some(&-4)); + /// assert_eq!(map.remove_last_value_at_point(4), Some(-4)); + /// + /// assert_eq!(map.get_last_value_at_point(4), Some(&-2)); + /// assert_eq!(map.remove_last_value_at_point(4), Some(-2)); + /// + /// assert_eq!(map.get_last_value_at_point(4), None); + /// assert_eq!(map.remove_last_value_at_point(4), None); + /// ``` + pub fn remove_last_value_at_point(&mut self, point: I) -> Option { + let mut cursor = self.inner.lower_bound_mut( + exclusive_comp_generator(point, Ordering::Greater), + SearchBoundCustom::Included, + ); + + if cursor.key().is_none() { + cursor.move_prev(); + } + + if let Some((key, value)) = cursor.key_value_mut() { + if key.contains_point(point) { + let last = value.pop().unwrap(); + + if value.is_empty() { + cursor.remove_current(); + } + + return Some(last); + } + } + + None + } + /// Appends the value to the `SmallVec` corresponding to the interval. /// /// If the given interval non-zero-overlaps one or more intervals already in the @@ -665,6 +721,11 @@ mod serde { #[cfg(test)] mod tests { + extern crate std; + + use alloc::vec; + use std::dbg; + use pretty_assertions::assert_eq; use super::*;