superset_map

B-tree-backed map whose keys are distinct supersets.
git clone https://git.philomathiclife.com/repos/superset_map
Log | Files | Refs | README

commit 0958d0fc632ed6514d4067f04f2f07830c3c53e0
parent f2f3b0ad01489b300457f736688353e42a506e67
Author: Zack Newman <zack@philomathiclife.com>
Date:   Mon, 23 Jun 2025 10:30:23 -0600

more lints

Diffstat:
MCargo.toml | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/lib.rs | 39+++------------------------------------
Msrc/superset_map.rs | 450+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Msrc/superset_set.rs | 81+++++++++++++++++++++++++++++++++++++++++--------------------------------------
4 files changed, 354 insertions(+), 284 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -9,7 +9,71 @@ license = "MIT OR Apache-2.0" name = "superset_map" readme = "README.md" repository = "https://git.philomathiclife.com/repos/superset_map/" -version = "0.3.1" +version = "0.3.2" + +[lints.rust] +ambiguous_negative_literals = { level = "deny", priority = -1 } +closure_returning_async_block = { level = "deny", priority = -1 } +deref_into_dyn_supertrait = { level = "deny", priority = -1 } +ffi_unwind_calls = { level = "deny", priority = -1 } +future_incompatible = { level = "deny", priority = -1 } +impl_trait_redundant_captures = { level = "deny", priority = -1 } +keyword-idents = { level = "deny", priority = -1 } +let_underscore = { level = "deny", priority = -1 } +linker_messages = { level = "deny", priority = -1 } +macro_use_extern_crate = { level = "deny", priority = -1 } +meta_variable_misuse = { level = "deny", priority = -1 } +missing_copy_implementations = { level = "deny", priority = -1 } +missing_debug_implementations = { level = "deny", priority = -1 } +missing_docs = { level = "deny", priority = -1 } +non_ascii_idents = { level = "deny", priority = -1 } +nonstandard_style = { level = "deny", priority = -1 } +redundant_imports = { level = "deny", priority = -1 } +redundant_lifetimes = { level = "deny", priority = -1 } +refining_impl_trait = { level = "deny", priority = -1 } +rust_2018_compatibility = { level = "deny", priority = -1 } +rust_2018_idioms = { level = "deny", priority = -1 } +rust_2021_compatibility = { level = "deny", priority = -1 } +rust_2024_compatibility = { level = "deny", priority = -1 } +single_use_lifetimes = { level = "deny", priority = -1 } +trivial_casts = { level = "deny", priority = -1 } +trivial_numeric_casts = { level = "deny", priority = -1 } +unit_bindings = { level = "deny", priority = -1 } +unknown_lints = { level = "deny", priority = -1 } +unnameable_types = { level = "deny", priority = -1 } +unreachable_pub = { level = "deny", priority = -1 } +unsafe_code = { level = "deny", priority = -1 } +unstable_features = { level = "deny", priority = -1 } +unused = { level = "deny", priority = -1 } +unused_crate_dependencies = { level = "deny", priority = -1 } +unused_import_braces = { level = "deny", priority = -1 } +unused_lifetimes = { level = "deny", priority = -1 } +unused_qualifications = { level = "deny", priority = -1 } +unused_results = { level = "deny", priority = -1 } +variant_size_differences = { level = "deny", priority = -1 } +warnings = { level = "deny", priority = -1 } + +[lints.clippy] +all = { level = "deny", priority = -1 } +cargo = { level = "deny", priority = -1 } +complexity = { level = "deny", priority = -1 } +correctness = { level = "deny", priority = -1 } +nursery = { level = "deny", priority = -1 } +pedantic = { level = "deny", priority = -1 } +perf = { level = "deny", priority = -1 } +restriction = { level = "deny", priority = -1 } +style = { level = "deny", priority = -1 } +suspicious = { level = "deny", priority = -1 } +# Noisy, opinionated, and likely don't prevent bugs or improve APIs. +arbitrary_source_item_ordering = "allow" +blanket_clippy_restriction_lints = "allow" +implicit_return = "allow" +min_ident_chars = "allow" +missing_trait_methods = "allow" +pub_use = "allow" +return_and_then = "allow" +semicolon_outside_block = "allow" +single_char_lifetime_names = "allow" [dependencies] -zfc = { version = "0.4.1", default-features = false } +zfc = { version = "0.4.2", default-features = false } diff --git a/src/lib.rs b/src/lib.rs @@ -131,44 +131,11 @@ //! assert!(iter.next().is_none()); //! ``` #![no_std] -#![feature(btree_cursors)] -#![deny( - unknown_lints, - future_incompatible, - let_underscore, - missing_docs, - nonstandard_style, - refining_impl_trait, - rust_2018_compatibility, - rust_2018_idioms, - rust_2021_compatibility, - rust_2024_compatibility, - unsafe_code, - unused, - warnings, - clippy::all, - clippy::cargo, - clippy::complexity, - clippy::correctness, - clippy::nursery, - clippy::pedantic, - clippy::perf, - clippy::restriction, - clippy::style, - clippy::suspicious -)] #![expect( - clippy::arbitrary_source_item_ordering, - clippy::blanket_clippy_restriction_lints, - clippy::implicit_return, - clippy::min_ident_chars, - clippy::missing_trait_methods, - clippy::pub_use, - clippy::return_and_then, - clippy::semicolon_outside_block, - clippy::single_char_lifetime_names, - reason = "noisy, opinionated, and likely doesn't prevent bugs or improve APIs" + unstable_features, + reason = "whole reason we require nightly is for btree_cursors" )] +#![feature(btree_cursors)] #[cfg(doc)] extern crate alloc; #[cfg(doc)] diff --git a/src/superset_map.rs b/src/superset_map.rs @@ -228,7 +228,7 @@ where *self = other; } else { other.into_iter().fold((), |(), (key, val)| { - self.insert(key, val); + _ = self.insert(key, val); }); } } @@ -387,40 +387,41 @@ where // the beginning of `map` or a `K` is not a subset of `key` // removing all `(K, V)`s where the `K` is a subset before we insert `(key, value)`. let mut cursor = self.map.lower_bound_mut(Bound::Included(&key)); - if let Some(ge) = cursor.peek_next() { - if ge.0.is_superset(&key) { - return false; - } - } - loop { - match cursor.prev() { - None => break, - Some(lt) => { - if key.is_proper_superset(lt.0) { - cursor.remove_next(); - } else { - cursor.next(); - break; + if let Some(ge) = cursor.peek_next() + && ge.0.is_superset(&key) + { + false + } else { + loop { + match cursor.prev() { + None => break, + Some(lt) => { + if key.is_proper_superset(lt.0) { + drop(cursor.remove_next()); + } else { + _ = cursor.next(); + break; + } } } } + // SAFETY: + // If `key` already existed in the map, then cursor + // would begin pointing at it. Since `Set::is_superset` + // returns true when both values are the same, we would + // immediately return from this function. This guarantees + // that `key` is unique before inserting. + // Since we only move to smaller values and each time we do + // we remove said value (or stop), the insert of `key` will occur after + // all smaller values and before larger values ensuring the sorted + // order of `map` is retained. + // Note that due to the requirements of `SetOrd`, a `K` that + // `is_proper_superset` another `K` is also strictly greater. + unsafe { + cursor.insert_before_unchecked(key, value); + } + true } - // SAFETY: - // If `key` already existed in the map, then cursor - // would begin pointing at it. Since `Set::is_superset` - // returns true when both values are the same, we would - // immediately return from this function. This guarantees - // that `key` is unique before inserting. - // Since we only move to smaller values and each time we do - // we remove said value (or stop), the insert of `key` will occur after - // all smaller values and before larger values ensuring the sorted - // order of `map` is retained. - // Note that due to the requirements of `SetOrd`, a `K` that - // `is_proper_superset` another `K` is also strictly greater. - unsafe { - cursor.insert_before_unchecked(key, value); - } - true } /// Allows for `SupersetSet::replace` to be implemented for supersets. #[inline] @@ -440,12 +441,13 @@ where Q: SetOrd + ?Sized, { let mut cursor = self.map.upper_bound_mut(Bound::Excluded(key)); - if let Some(lt) = cursor.peek_prev() { - if lt.0.borrow().is_proper_subset(key) { - return cursor.remove_prev(); - } + if let Some(lt) = cursor.peek_prev() + && lt.0.borrow().is_proper_subset(key) + { + cursor.remove_prev() + } else { + None } - None } /// Removes the greatest subset of key from the map, returning the key and value if such a subset exists. /// The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type. @@ -456,12 +458,13 @@ where Q: SetOrd + ?Sized, { let mut cursor = self.map.upper_bound_mut(Bound::Included(key)); - if let Some(le) = cursor.peek_prev() { - if le.0.borrow().is_subset(key) { - return cursor.remove_prev(); - } + if let Some(le) = cursor.peek_prev() + && le.0.borrow().is_subset(key) + { + cursor.remove_prev() + } else { + None } - None } /// Removes the least proper superset of key from the map, returning the key and value if such a superset exists. /// The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type. @@ -472,12 +475,13 @@ where Q: SetOrd + ?Sized, { let mut cursor = self.map.lower_bound_mut(Bound::Excluded(key)); - if let Some(gt) = cursor.peek_next() { - if gt.0.borrow().is_proper_superset(key) { - return cursor.remove_next(); - } + if let Some(gt) = cursor.peek_next() + && gt.0.borrow().is_proper_superset(key) + { + cursor.remove_next() + } else { + None } - None } /// Removes the least superset of key from the map, returning the key and value if such a superset exists. /// The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type. @@ -488,12 +492,13 @@ where Q: SetOrd + ?Sized, { let mut cursor = self.map.lower_bound_mut(Bound::Included(key)); - if let Some(ge) = cursor.peek_next() { - if ge.0.borrow().is_superset(key) { - return cursor.remove_next(); - } + if let Some(ge) = cursor.peek_next() + && ge.0.borrow().is_superset(key) + { + cursor.remove_next() + } else { + None } - None } /// Removes all proper subsets of key from the map, returning the count removed. /// The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match @@ -512,7 +517,7 @@ where let mut count = 0; while let Some(lt) = cursor.prev() { if lt.0.borrow().is_proper_subset(key) { - cursor.remove_next(); + drop(cursor.remove_next()); count += 1; } else { return count; @@ -537,7 +542,7 @@ where let mut count = 0; while let Some(gt) = cursor.next() { if gt.0.borrow().is_proper_superset(key) { - cursor.remove_prev(); + drop(cursor.remove_prev()); count += 1; } else { return count; @@ -565,11 +570,11 @@ where // while calling `is_proper_subset` on the other elements. if let Some(le) = cursor.prev() { if le.0.borrow().is_subset(key) { - cursor.remove_next(); + drop(cursor.remove_next()); count += 1; while let Some(lt) = cursor.prev() { if lt.0.borrow().is_proper_subset(key) { - cursor.remove_next(); + drop(cursor.remove_next()); count += 1; } else { return count; @@ -600,12 +605,12 @@ where // while calling `is_proper_superset` on the other elements. if let Some(ge) = cursor.next() { if ge.0.borrow().is_superset(key) { - cursor.remove_prev(); + drop(cursor.remove_prev()); // `count` never exceeds `self.map.len()`; thus overflow is no worry. count += 1; while let Some(gt) = cursor.next() { if gt.0.borrow().is_proper_superset(key) { - cursor.remove_prev(); + drop(cursor.remove_prev()); // `count` never exceeds `self.map.len()`; thus overflow is no worry. count += 1; } else { @@ -635,7 +640,7 @@ where #[inline] fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T) { iter.into_iter().fold((), |(), (k, v)| { - self.insert(k, v); + _ = self.insert(k, v); }); } } @@ -647,7 +652,7 @@ where #[inline] fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T) { iter.into_iter().fold((), |(), (k, v)| { - self.insert(*k, *v); + _ = self.insert(*k, *v); }); } } @@ -711,7 +716,7 @@ impl<'a, K, V> IntoIterator for &'a mut SupersetMap<K, V> { #[cfg(test)] mod tests { use super::{ - super::zfc::{num_bigint::BigUint, BoundedCardinality, Cardinality, Set}, + super::zfc::{BoundedCardinality, Cardinality, Set, num_bigint::BigUint}, SetOrd, SupersetMap, }; use core::{borrow::Borrow, cmp::Ordering}; @@ -779,23 +784,26 @@ mod tests { #[test] fn test_insert() { let mut map = SupersetMap::new(); - map.insert(ClosedInterval { min: 0, max: 3 }, ()); - map.insert(ClosedInterval { min: 0, max: 3 }, ()); - map.insert(ClosedInterval { min: 0, max: 4 }, ()); - map.insert(ClosedInterval { min: 1, max: 4 }, ()); - map.insert(ClosedInterval { min: 4, max: 6 }, ()); - map.insert(ClosedInterval { min: 2, max: 7 }, ()); - map.insert(ClosedInterval { min: 10, max: 17 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 4 }, ()); + _ = map.insert(ClosedInterval { min: 1, max: 4 }, ()); + _ = map.insert(ClosedInterval { min: 4, max: 6 }, ()); + _ = map.insert(ClosedInterval { min: 2, max: 7 }, ()); + _ = map.insert(ClosedInterval { min: 10, max: 17 }, ()); let mut keys = map.into_keys(); - assert!(keys - .next() - .map_or(false, |set| set == ClosedInterval { min: 0, max: 4 })); - assert!(keys - .next() - .map_or(false, |set| set == ClosedInterval { min: 2, max: 7 })); - assert!(keys - .next() - .map_or(false, |set| set == ClosedInterval { min: 10, max: 17 })); + assert!( + keys.next() + .map_or(false, |set| set == ClosedInterval { min: 0, max: 4 }) + ); + assert!( + keys.next() + .map_or(false, |set| set == ClosedInterval { min: 2, max: 7 }) + ); + assert!( + keys.next() + .map_or(false, |set| set == ClosedInterval { min: 10, max: 17 }) + ); assert!(keys.next().is_none()); assert!(keys.next().is_none()); assert!(keys.next().is_none()); @@ -803,31 +811,35 @@ mod tests { #[test] fn test_append() { let mut map = SupersetMap::new(); - map.insert(ClosedInterval { min: 0, max: 3 }, ()); - map.insert(ClosedInterval { min: 0, max: 3 }, ()); - map.insert(ClosedInterval { min: 0, max: 4 }, ()); - map.insert(ClosedInterval { min: 1, max: 4 }, ()); - map.insert(ClosedInterval { min: 4, max: 6 }, ()); - map.insert(ClosedInterval { min: 2, max: 7 }, ()); - map.insert(ClosedInterval { min: 10, max: 17 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 4 }, ()); + _ = map.insert(ClosedInterval { min: 1, max: 4 }, ()); + _ = map.insert(ClosedInterval { min: 4, max: 6 }, ()); + _ = map.insert(ClosedInterval { min: 2, max: 7 }, ()); + _ = map.insert(ClosedInterval { min: 10, max: 17 }, ()); let mut map2 = SupersetMap::new(); - map2.insert(ClosedInterval { min: 0, max: 1 }, ()); - map2.insert(ClosedInterval { min: 1, max: 14 }, ()); - map2.insert(ClosedInterval { min: 11, max: 18 }, ()); + _ = map2.insert(ClosedInterval { min: 0, max: 1 }, ()); + _ = map2.insert(ClosedInterval { min: 1, max: 14 }, ()); + _ = map2.insert(ClosedInterval { min: 11, max: 18 }, ()); map.append(map2); let mut keys = map.into_keys(); - assert!(keys - .next() - .map_or(false, |set| set == ClosedInterval { min: 0, max: 4 })); - assert!(keys - .next() - .map_or(false, |set| set == ClosedInterval { min: 1, max: 14 })); - assert!(keys - .next() - .map_or(false, |set| set == ClosedInterval { min: 10, max: 17 })); - assert!(keys - .next() - .map_or(false, |set| set == ClosedInterval { min: 11, max: 18 })); + assert!( + keys.next() + .map_or(false, |set| set == ClosedInterval { min: 0, max: 4 }) + ); + assert!( + keys.next() + .map_or(false, |set| set == ClosedInterval { min: 1, max: 14 }) + ); + assert!( + keys.next() + .map_or(false, |set| set == ClosedInterval { min: 10, max: 17 }) + ); + assert!( + keys.next() + .map_or(false, |set| set == ClosedInterval { min: 11, max: 18 }) + ); assert!(keys.next().is_none()); assert!(keys.next().is_none()); assert!(keys.next().is_none()); @@ -835,13 +847,13 @@ mod tests { #[test] fn test_contains() { let mut map = SupersetMap::new(); - map.insert(ClosedInterval { min: 0, max: 3 }, ()); - map.insert(ClosedInterval { min: 0, max: 3 }, ()); - map.insert(ClosedInterval { min: 0, max: 4 }, ()); - map.insert(ClosedInterval { min: 1, max: 4 }, ()); - map.insert(ClosedInterval { min: 4, max: 6 }, ()); - map.insert(ClosedInterval { min: 2, max: 7 }, ()); - map.insert(ClosedInterval { min: 10, max: 17 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 4 }, ()); + _ = map.insert(ClosedInterval { min: 1, max: 4 }, ()); + _ = map.insert(ClosedInterval { min: 4, max: 6 }, ()); + _ = map.insert(ClosedInterval { min: 2, max: 7 }, ()); + _ = map.insert(ClosedInterval { min: 10, max: 17 }, ()); assert!(map.contains_proper_subset(&ClosedInterval { min: 0, max: 10 })); assert!(!map.contains_proper_subset(&ClosedInterval { min: 10, max: 17 })); assert!(!map.contains_proper_subset(&ClosedInterval { min: 210, max: 217 })); @@ -858,116 +870,140 @@ mod tests { #[test] fn test_get() { let mut map = SupersetMap::new(); - map.insert(ClosedInterval { min: 0, max: 3 }, ()); - map.insert(ClosedInterval { min: 0, max: 3 }, ()); - map.insert(ClosedInterval { min: 0, max: 4 }, ()); - map.insert(ClosedInterval { min: 1, max: 4 }, ()); - map.insert(ClosedInterval { min: 4, max: 6 }, ()); - map.insert(ClosedInterval { min: 2, max: 7 }, ()); - map.insert(ClosedInterval { min: 10, max: 17 }, ()); - assert!(map - .get_greatest_proper_subset_key_value(&ClosedInterval { min: 0, max: 10 }) - .map_or(false, |(key, _)| *key == ClosedInterval { min: 2, max: 7 })); - assert!(map - .get_greatest_proper_subset_key_value(&ClosedInterval { min: 10, max: 17 }) - .map_or(true, |_| false)); - assert!(map - .get_greatest_proper_subset_key_value(&ClosedInterval { min: 210, max: 217 }) - .map_or(true, |_| false)); - assert!(map - .get_least_proper_superset_key_value(&ClosedInterval { min: 3, max: 4 }) - .map_or(false, |(key, _)| *key == ClosedInterval { min: 0, max: 4 })); - assert!(map - .get_least_proper_superset_key_value(&ClosedInterval { min: 10, max: 17 }) - .map_or(true, |_| false)); - assert!(map - .get_least_proper_superset_key_value(&ClosedInterval { min: 210, max: 217 }) - .map_or(true, |_| false)); - assert!(map - .get_greatest_subset_key_value(&ClosedInterval { min: 0, max: 10 }) - .map_or(false, |(key, _)| *key == ClosedInterval { min: 2, max: 7 })); - assert!(map - .get_greatest_subset_key_value(&ClosedInterval { min: 10, max: 17 }) - .map_or(false, |(key, _)| *key - == ClosedInterval { min: 10, max: 17 })); - assert!(map - .get_greatest_subset_key_value(&ClosedInterval { min: 210, max: 217 }) - .map_or(true, |_| false)); - assert!(map - .get_least_superset_key_value(&ClosedInterval { min: 3, max: 4 }) - .map_or(false, |(key, _)| *key == ClosedInterval { min: 0, max: 4 })); - assert!(map - .get_least_superset_key_value(&ClosedInterval { min: 10, max: 17 }) - .map_or(false, |(key, _)| *key - == ClosedInterval { min: 10, max: 17 })); - assert!(map - .get_least_superset_key_value(&ClosedInterval { min: 210, max: 217 }) - .map_or(true, |_| false)); + _ = map.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 4 }, ()); + _ = map.insert(ClosedInterval { min: 1, max: 4 }, ()); + _ = map.insert(ClosedInterval { min: 4, max: 6 }, ()); + _ = map.insert(ClosedInterval { min: 2, max: 7 }, ()); + _ = map.insert(ClosedInterval { min: 10, max: 17 }, ()); + assert!( + map.get_greatest_proper_subset_key_value(&ClosedInterval { min: 0, max: 10 }) + .map_or(false, |(key, _)| *key == ClosedInterval { min: 2, max: 7 }) + ); + assert!( + map.get_greatest_proper_subset_key_value(&ClosedInterval { min: 10, max: 17 }) + .map_or(true, |_| false) + ); + assert!( + map.get_greatest_proper_subset_key_value(&ClosedInterval { min: 210, max: 217 }) + .map_or(true, |_| false) + ); + assert!( + map.get_least_proper_superset_key_value(&ClosedInterval { min: 3, max: 4 }) + .map_or(false, |(key, _)| *key == ClosedInterval { min: 0, max: 4 }) + ); + assert!( + map.get_least_proper_superset_key_value(&ClosedInterval { min: 10, max: 17 }) + .map_or(true, |_| false) + ); + assert!( + map.get_least_proper_superset_key_value(&ClosedInterval { min: 210, max: 217 }) + .map_or(true, |_| false) + ); + assert!( + map.get_greatest_subset_key_value(&ClosedInterval { min: 0, max: 10 }) + .map_or(false, |(key, _)| *key == ClosedInterval { min: 2, max: 7 }) + ); + assert!( + map.get_greatest_subset_key_value(&ClosedInterval { min: 10, max: 17 }) + .map_or(false, |(key, _)| *key + == ClosedInterval { min: 10, max: 17 }) + ); + assert!( + map.get_greatest_subset_key_value(&ClosedInterval { min: 210, max: 217 }) + .map_or(true, |_| false) + ); + assert!( + map.get_least_superset_key_value(&ClosedInterval { min: 3, max: 4 }) + .map_or(false, |(key, _)| *key == ClosedInterval { min: 0, max: 4 }) + ); + assert!( + map.get_least_superset_key_value(&ClosedInterval { min: 10, max: 17 }) + .map_or(false, |(key, _)| *key + == ClosedInterval { min: 10, max: 17 }) + ); + assert!( + map.get_least_superset_key_value(&ClosedInterval { min: 210, max: 217 }) + .map_or(true, |_| false) + ); } #[test] fn test_remove() { let mut map = SupersetMap::new(); - map.insert(ClosedInterval { min: 0, max: 3 }, ()); - map.insert(ClosedInterval { min: 0, max: 3 }, ()); - map.insert(ClosedInterval { min: 0, max: 4 }, ()); - map.insert(ClosedInterval { min: 1, max: 4 }, ()); - map.insert(ClosedInterval { min: 4, max: 6 }, ()); - map.insert(ClosedInterval { min: 2, max: 7 }, ()); - map.insert(ClosedInterval { min: 10, max: 17 }, ()); - assert!(map - .remove_greatest_proper_subset(&ClosedInterval { min: 0, max: 10 }) - .map_or(false, |(key, _)| key == ClosedInterval { min: 2, max: 7 })); - assert!(map - .remove_greatest_proper_subset(&ClosedInterval { min: 10, max: 17 }) - .map_or(true, |_| false)); - assert!(map - .remove_greatest_proper_subset(&ClosedInterval { min: 210, max: 217 }) - .map_or(true, |_| false)); - assert!(map - .remove_least_proper_superset(&ClosedInterval { min: 3, max: 4 }) - .map_or(false, |(key, _)| key == ClosedInterval { min: 0, max: 4 })); - assert!(map - .remove_least_proper_superset(&ClosedInterval { min: 10, max: 17 }) - .map_or(true, |_| false)); - assert!(map - .remove_least_proper_superset(&ClosedInterval { min: 210, max: 217 }) - .map_or(true, |_| false)); - assert!(map - .remove_greatest_subset(&ClosedInterval { min: 0, max: 10 }) - .map_or(true, |_| false)); - assert!(map - .remove_greatest_subset(&ClosedInterval { min: 10, max: 17 }) - .map_or(false, |(key, _)| key == ClosedInterval { min: 10, max: 17 })); - assert!(map - .remove_greatest_subset(&ClosedInterval { min: 210, max: 217 }) - .map_or(true, |_| false)); - assert!(map - .remove_least_superset(&ClosedInterval { min: 3, max: 4 }) - .map_or(true, |_| false)); - assert!(map - .remove_least_superset(&ClosedInterval { min: 10, max: 17 }) - .map_or(true, |_| false)); - assert!(map - .remove_least_superset(&ClosedInterval { min: 210, max: 217 }) - .map_or(true, |_| false)); + _ = map.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map.insert(ClosedInterval { min: 0, max: 4 }, ()); + _ = map.insert(ClosedInterval { min: 1, max: 4 }, ()); + _ = map.insert(ClosedInterval { min: 4, max: 6 }, ()); + _ = map.insert(ClosedInterval { min: 2, max: 7 }, ()); + _ = map.insert(ClosedInterval { min: 10, max: 17 }, ()); + assert!( + map.remove_greatest_proper_subset(&ClosedInterval { min: 0, max: 10 }) + .map_or(false, |(key, _)| key == ClosedInterval { min: 2, max: 7 }) + ); + assert!( + map.remove_greatest_proper_subset(&ClosedInterval { min: 10, max: 17 }) + .map_or(true, |_| false) + ); + assert!( + map.remove_greatest_proper_subset(&ClosedInterval { min: 210, max: 217 }) + .map_or(true, |_| false) + ); + assert!( + map.remove_least_proper_superset(&ClosedInterval { min: 3, max: 4 }) + .map_or(false, |(key, _)| key == ClosedInterval { min: 0, max: 4 }) + ); + assert!( + map.remove_least_proper_superset(&ClosedInterval { min: 10, max: 17 }) + .map_or(true, |_| false) + ); + assert!( + map.remove_least_proper_superset(&ClosedInterval { min: 210, max: 217 }) + .map_or(true, |_| false) + ); + assert!( + map.remove_greatest_subset(&ClosedInterval { min: 0, max: 10 }) + .map_or(true, |_| false) + ); + assert!( + map.remove_greatest_subset(&ClosedInterval { min: 10, max: 17 }) + .map_or(false, |(key, _)| key == ClosedInterval { min: 10, max: 17 }) + ); + assert!( + map.remove_greatest_subset(&ClosedInterval { min: 210, max: 217 }) + .map_or(true, |_| false) + ); + assert!( + map.remove_least_superset(&ClosedInterval { min: 3, max: 4 }) + .map_or(true, |_| false) + ); + assert!( + map.remove_least_superset(&ClosedInterval { min: 10, max: 17 }) + .map_or(true, |_| false) + ); + assert!( + map.remove_least_superset(&ClosedInterval { min: 210, max: 217 }) + .map_or(true, |_| false) + ); let mut map2 = SupersetMap::new(); - map2.insert(ClosedInterval { min: 0, max: 3 }, ()); - map2.insert(ClosedInterval { min: 0, max: 3 }, ()); - map2.insert(ClosedInterval { min: 0, max: 4 }, ()); - map2.insert(ClosedInterval { min: 1, max: 4 }, ()); - map2.insert(ClosedInterval { min: 4, max: 6 }, ()); - map2.insert(ClosedInterval { min: 2, max: 7 }, ()); - map2.insert(ClosedInterval { min: 10, max: 17 }, ()); + _ = map2.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map2.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map2.insert(ClosedInterval { min: 0, max: 4 }, ()); + _ = map2.insert(ClosedInterval { min: 1, max: 4 }, ()); + _ = map2.insert(ClosedInterval { min: 4, max: 6 }, ()); + _ = map2.insert(ClosedInterval { min: 2, max: 7 }, ()); + _ = map2.insert(ClosedInterval { min: 10, max: 17 }, ()); assert!(map2.remove_supersets(&ClosedInterval { min: 0, max: 20 }) == 0); assert!(map2.remove_subsets(&ClosedInterval { min: 0, max: 1 }) == 0); assert!(map2.remove_subsets(&ClosedInterval { min: 0, max: 20 }) == 3); - map2.insert(ClosedInterval { min: 0, max: 3 }, ()); - map2.insert(ClosedInterval { min: 0, max: 3 }, ()); - map2.insert(ClosedInterval { min: 0, max: 4 }, ()); - map2.insert(ClosedInterval { min: 1, max: 4 }, ()); - map2.insert(ClosedInterval { min: 4, max: 6 }, ()); - map2.insert(ClosedInterval { min: 2, max: 7 }, ()); - map2.insert(ClosedInterval { min: 10, max: 17 }, ()); + _ = map2.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map2.insert(ClosedInterval { min: 0, max: 3 }, ()); + _ = map2.insert(ClosedInterval { min: 0, max: 4 }, ()); + _ = map2.insert(ClosedInterval { min: 1, max: 4 }, ()); + _ = map2.insert(ClosedInterval { min: 4, max: 6 }, ()); + _ = map2.insert(ClosedInterval { min: 2, max: 7 }, ()); + _ = map2.insert(ClosedInterval { min: 10, max: 17 }, ()); assert!(map2.remove_supersets(&ClosedInterval { min: 3, max: 4 }) == 2); } } diff --git a/src/superset_set.rs b/src/superset_set.rs @@ -13,6 +13,7 @@ use core::{ /// A lazy iterator producing elements in the intersection of `SupersetSet`s. /// /// This `struct` is created by [`SupersetSet::intersection`]. +#[expect(missing_debug_implementations, reason = "Iter does not, so we do not")] #[derive(Clone)] pub struct Intersection<'a, T> { /// Iterator for the first `SupersetSet`. @@ -93,6 +94,7 @@ where /// An owning iterator over the items of a `SupersetSet`. /// /// This `struct` is created by [`SupersetSet::into_iter`] (provided by [`IntoIterator`]). +#[derive(Debug)] pub struct IntoIter<T> { /// Iterator of the values in a `SupersetSet`. iter: IntoKeys<T, ()>, @@ -128,7 +130,7 @@ impl<T> Iterator for IntoIter<T> { /// An iterator over the items of a `SupersetSet`. /// /// This `struct` is created by [`SupersetSet::iter`]. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Iter<'a, T> { /// Iterator of the values in a `SupersetSet`. iter: Keys<'a, T, ()>, @@ -164,7 +166,7 @@ impl<'a, T> Iterator for Iter<'a, T> { /// An iterator over a sub-range of items in a `SupersetSet`. /// /// This `struct` is created by [`SupersetSet::range`]. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Range<'a, T> { /// Range iterator for a `SupersetSet`. iter: btree_map::Range<'a, T, ()>, @@ -574,7 +576,7 @@ where None } }; - self.insert(value); + _ = self.insert(value); prev } /// Retains only the elements specified by the predicate. @@ -725,6 +727,7 @@ where /// A lazy iterator producing elements in the union of `SupersetSet`s. /// /// This `struct` is created by [`SupersetSet::union`]. +#[expect(missing_debug_implementations, reason = "Iter does not, so we do not")] #[derive(Clone)] pub struct Union<'a, T> { /// Iterator from the first `SupersetSet`. @@ -871,21 +874,21 @@ mod tests { #[test] fn test_union() { let mut set1 = SupersetSet::new(); - set1.insert(ClosedInterval { min: 14, max: 19 }); - set1.insert(ClosedInterval { min: 10, max: 12 }); - set1.insert(ClosedInterval { min: 0, max: 3 }); - set1.insert(ClosedInterval { min: 0, max: 2 }); - set1.insert(ClosedInterval { min: 1, max: 4 }); - set1.insert(ClosedInterval { min: 20, max: 22 }); - set1.insert(ClosedInterval { min: 25, max: 26 }); - set1.insert(ClosedInterval { min: 26, max: 27 }); + _ = set1.insert(ClosedInterval { min: 14, max: 19 }); + _ = set1.insert(ClosedInterval { min: 10, max: 12 }); + _ = set1.insert(ClosedInterval { min: 0, max: 3 }); + _ = set1.insert(ClosedInterval { min: 0, max: 2 }); + _ = set1.insert(ClosedInterval { min: 1, max: 4 }); + _ = set1.insert(ClosedInterval { min: 20, max: 22 }); + _ = set1.insert(ClosedInterval { min: 25, max: 26 }); + _ = set1.insert(ClosedInterval { min: 26, max: 27 }); let mut set2 = SupersetSet::new(); - set2.insert(ClosedInterval { min: 10, max: 12 }); - set2.insert(ClosedInterval { min: 14, max: 16 }); - set2.insert(ClosedInterval { min: 0, max: 3 }); - set2.insert(ClosedInterval { min: 3, max: 4 }); - set2.insert(ClosedInterval { min: 23, max: 25 }); - set2.insert(ClosedInterval { min: 25, max: 27 }); + _ = set2.insert(ClosedInterval { min: 10, max: 12 }); + _ = set2.insert(ClosedInterval { min: 14, max: 16 }); + _ = set2.insert(ClosedInterval { min: 0, max: 3 }); + _ = set2.insert(ClosedInterval { min: 3, max: 4 }); + _ = set2.insert(ClosedInterval { min: 23, max: 25 }); + _ = set2.insert(ClosedInterval { min: 25, max: 27 }); let mut union = set1.union(&set2); assert!(union.next() == Some(&ClosedInterval { min: 0, max: 3 })); assert!(union.next() == Some(&ClosedInterval { min: 1, max: 4 })); @@ -901,21 +904,21 @@ mod tests { #[test] fn test_intersection() { let mut set1 = SupersetSet::new(); - set1.insert(ClosedInterval { min: 14, max: 19 }); - set1.insert(ClosedInterval { min: 10, max: 12 }); - set1.insert(ClosedInterval { min: 0, max: 3 }); - set1.insert(ClosedInterval { min: 0, max: 2 }); - set1.insert(ClosedInterval { min: 1, max: 4 }); - set1.insert(ClosedInterval { min: 20, max: 22 }); - set1.insert(ClosedInterval { min: 25, max: 26 }); - set1.insert(ClosedInterval { min: 26, max: 27 }); + _ = set1.insert(ClosedInterval { min: 14, max: 19 }); + _ = set1.insert(ClosedInterval { min: 10, max: 12 }); + _ = set1.insert(ClosedInterval { min: 0, max: 3 }); + _ = set1.insert(ClosedInterval { min: 0, max: 2 }); + _ = set1.insert(ClosedInterval { min: 1, max: 4 }); + _ = set1.insert(ClosedInterval { min: 20, max: 22 }); + _ = set1.insert(ClosedInterval { min: 25, max: 26 }); + _ = set1.insert(ClosedInterval { min: 26, max: 27 }); let mut set2 = SupersetSet::new(); - set2.insert(ClosedInterval { min: 10, max: 12 }); - set2.insert(ClosedInterval { min: 14, max: 16 }); - set2.insert(ClosedInterval { min: 0, max: 3 }); - set2.insert(ClosedInterval { min: 3, max: 4 }); - set2.insert(ClosedInterval { min: 23, max: 25 }); - set2.insert(ClosedInterval { min: 25, max: 27 }); + _ = set2.insert(ClosedInterval { min: 10, max: 12 }); + _ = set2.insert(ClosedInterval { min: 14, max: 16 }); + _ = set2.insert(ClosedInterval { min: 0, max: 3 }); + _ = set2.insert(ClosedInterval { min: 3, max: 4 }); + _ = set2.insert(ClosedInterval { min: 23, max: 25 }); + _ = set2.insert(ClosedInterval { min: 25, max: 27 }); let mut intersection = set1.intersection(&set2); assert!(intersection.next() == Some(&ClosedInterval { min: 0, max: 3 })); assert!(intersection.next() == Some(&ClosedInterval { min: 3, max: 4 })); @@ -930,14 +933,14 @@ mod tests { #[test] fn test_replace() { let mut set = SupersetSet::new(); - set.insert(ClosedInterval { min: 14, max: 19 }); - set.insert(ClosedInterval { min: 10, max: 12 }); - set.insert(ClosedInterval { min: 0, max: 3 }); - set.insert(ClosedInterval { min: 0, max: 2 }); - set.insert(ClosedInterval { min: 1, max: 4 }); - set.insert(ClosedInterval { min: 20, max: 22 }); - set.insert(ClosedInterval { min: 25, max: 26 }); - set.insert(ClosedInterval { min: 26, max: 27 }); + _ = set.insert(ClosedInterval { min: 14, max: 19 }); + _ = set.insert(ClosedInterval { min: 10, max: 12 }); + _ = set.insert(ClosedInterval { min: 0, max: 3 }); + _ = set.insert(ClosedInterval { min: 0, max: 2 }); + _ = set.insert(ClosedInterval { min: 1, max: 4 }); + _ = set.insert(ClosedInterval { min: 20, max: 22 }); + _ = set.insert(ClosedInterval { min: 25, max: 26 }); + _ = set.insert(ClosedInterval { min: 26, max: 27 }); // Does not replace proper supersets. assert!( set.replace(ClosedInterval { min: 20, max: 21 }).is_none()