Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,8 +1,8 @@ [package] name = "limq" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "0BSD" # https://crates.io/category_slugs categories = [ "data-structures" ] keywords = [ "queue", "bounded" ] Index: src/lib.rs ================================================================== --- src/lib.rs +++ src/lib.rs @@ -55,10 +55,16 @@ let q = max_len.map_or_else(VecDeque::new, VecDeque::with_capacity); Self { q, max_len } } + + /// Clear all nodes from queue. + #[inline] + pub fn clear(&mut self) { + self.q.clear(); + } /// Change the limit of the queue. /// /// Does not drain overflow elements if the new limit is lower than the /// current number of elements in queue. This can be done manually by @@ -92,10 +98,35 @@ #[inline] #[must_use] pub fn is_empty(&self) -> bool { self.q.is_empty() } + + /// Returns a boolean indicating whether the queue is full. + /// + /// If no limit has been configured, this will always return `false`. + /// + /// ``` + /// use limq::LimQ; + /// + /// // Construct a queue with a maximum 1 element length limit + /// let mut q: LimQ = LimQ::new(Some(1)); + /// + /// assert!(!q.is_full()); + /// + /// // Fill queue up + /// q.try_push(1).unwrap(); + /// + /// assert!(q.is_full()); + /// ``` + #[inline] + #[must_use] + pub fn is_full(&self) -> bool { + self + .max_len + .map_or(false, |max_len| self.q.len() >= max_len) + } /// Drop elements that overflow the queue limit (if a limit has been set). /// /// ``` /// use limq::LimQ; Index: www/changelog.md ================================================================== --- www/changelog.md +++ www/changelog.md @@ -1,19 +1,38 @@ # Change Log ## [Unreleased] -[Details](/vdiff?from=limq-0.1.0&to=trunk) +[Details](/vdiff?from=limq-0.1.2&to=trunk) ### Added -- Add an assertion message when a zero maximum length has been specified. - ### Changed ### Removed +--- + +## [0.1.2] - 2024-09-13 + +[Details](/vdiff?from=limq-0.1.1&to=limq-0.1.2) + +### Added + +- Add `LimQ::is_full()` function. +- Add `LimQ::clear()` function. + +--- + +## [0.1.1] - 2024-09-12 + +[Details](/vdiff?from=limq-0.1.0&to=limq-0.1.1) + +### Added + +- Add an assertion message when a zero maximum length has been specified. + --- ## [0.1.0] - 2024-04-09 First release.