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 29f246fe5105e39719018e882f3f7cfa4895e6d4
parent 1acebd4c8a10b8658b9e54b4ec433b7ea8a32f47
Author: Zack Newman <zack@philomathiclife.com>
Date:   Tue,  5 Sep 2023 16:41:36 -0600

conform to new reqs from zfc crate

Diffstat:
MCargo.toml | 4++--
MREADME.md | 11+++++++----
Msrc/lib.rs | 11+++++++----
Msrc/superset_map.rs | 13++++++++++---
Msrc/superset_set.rs | 23+++++++++++++++++------
5 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -10,14 +10,14 @@ name = "superset_map" readme = "README.md" repository = "https://git.philomathiclife.com/repos/superset_map/" rust-version = "1.69" -version = "0.1.1" +version = "0.2.0" [lib] name = "superset_map" path = "src/lib.rs" [dependencies] -zfc = { version = "0.1.1", default-features = false } +zfc = { version = "0.3.0", default-features = false } [dev-dependencies] num-bigint = { version = "0.4.4", default-features = false } diff --git a/README.md b/README.md @@ -13,7 +13,7 @@ use core::borrow::Borrow; use core::cmp::Ordering; use num_bigint::BigUint; use superset_map::{SetOrd, SupersetSet}; -use zfc::{Cardinality, Set}; +use zfc::{BoundedCardinality, Cardinality, Set}; #[derive(Clone, Copy, Eq, PartialEq)] struct ShortAscii<'a> { val: &'a [u8], @@ -78,8 +78,11 @@ impl<'a> Ord for WildcardAscii<'a> { } impl<'a> Set for WildcardAscii<'a> { type Elem = ShortAscii<'a>; - fn cardinality(&self) -> Cardinality { - Cardinality::Finite(match *self { + fn bounded_cardinality(&self) -> BoundedCardinality { + BoundedCardinality::new_exact(self.cardinality().unwrap()) + } + fn cardinality(&self) -> Option<Cardinality> { + Some(Cardinality::Finite(match *self { WildcardAscii::Plain(_) => BigUint::new(vec![1]), // Geometric series. WildcardAscii::Wildcard(v) => { @@ -87,7 +90,7 @@ impl<'a> Set for WildcardAscii<'a> { - BigUint::new(vec![1])) / BigUint::new(vec![127]) } - }) + })) } fn contains<Q>(&self, elem: &Q) -> bool where diff --git a/src/lib.rs b/src/lib.rs @@ -16,7 +16,7 @@ //! use core::cmp::Ordering; //! use num_bigint::BigUint; //! use superset_map::{SetOrd, SupersetSet}; -//! use zfc::{Cardinality, Set}; +//! use zfc::{BoundedCardinality, Cardinality, Set}; //! #[derive(Clone, Copy, Eq, PartialEq)] //! struct ShortAscii<'a> { //! val: &'a [u8], @@ -81,8 +81,11 @@ //! } //! impl<'a> Set for WildcardAscii<'a> { //! type Elem = ShortAscii<'a>; -//! fn cardinality(&self) -> Cardinality { -//! Cardinality::Finite(match *self { +//! fn bounded_cardinality(&self) -> BoundedCardinality { +//! BoundedCardinality::new_exact(self.cardinality().unwrap()) +//! } +//! fn cardinality(&self) -> Option<Cardinality> { +//! Some(Cardinality::Finite(match *self { //! WildcardAscii::Plain(_) => BigUint::new(vec![1]), //! // Geometric series. //! WildcardAscii::Wildcard(v) => { @@ -90,7 +93,7 @@ //! - BigUint::new(vec![1])) //! / BigUint::new(vec![127]) //! } -//! }) +//! })) //! } //! fn contains<Q>(&self, elem: &Q) -> bool //! where diff --git a/src/superset_map.rs b/src/superset_map.rs @@ -742,7 +742,7 @@ mod tests { use core::borrow::Borrow; use core::cmp::Ordering; use num_bigint::BigUint; - use zfc::{Cardinality, Set}; + use zfc::{BoundedCardinality, Cardinality, Set}; #[derive(PartialEq, Eq)] struct ClosedInterval { min: usize, @@ -776,8 +776,15 @@ mod tests { } impl Set for ClosedInterval { type Elem = usize; - fn cardinality(&self) -> Cardinality { - Cardinality::Finite(BigUint::from(self.max - self.min) + BigUint::from(1usize)) + fn bounded_cardinality(&self) -> BoundedCardinality { + BoundedCardinality::from_biguint_exact( + BigUint::from(self.max - self.min) + BigUint::from(1usize), + ) + } + fn cardinality(&self) -> Option<Cardinality> { + Some(Cardinality::Finite( + BigUint::from(self.max - self.min) + BigUint::from(1usize), + )) } fn contains<Q>(&self, elem: &Q) -> bool where diff --git a/src/superset_set.rs b/src/superset_set.rs @@ -30,7 +30,7 @@ use core::borrow::Borrow; use core::hash::{Hash, Hasher}; use core::iter::FusedIterator; use core::ops::{BitAnd, BitOr, Bound, RangeBounds}; -use zfc::{Cardinality, Set}; +use zfc::{BoundedCardinality, Cardinality, Set}; /// A lazy iterator producing elements in the intersection of `SupersetSet`s. /// /// This `struct` is created by [`SupersetSet::intersection`]. @@ -722,8 +722,12 @@ where { type Elem = T; #[inline] - fn cardinality(&self) -> Cardinality { - Cardinality::Finite(self.len().into()) + fn bounded_cardinality(&self) -> BoundedCardinality { + BoundedCardinality::from_biguint_exact(self.len().into()) + } + #[inline] + fn cardinality(&self) -> Option<Cardinality> { + Some(Cardinality::Finite(self.len().into())) } #[inline] fn contains<Q>(&self, elem: &Q) -> bool @@ -827,7 +831,7 @@ mod tests { use core::borrow::Borrow; use core::cmp::Ordering; use num_bigint::BigUint; - use zfc::{Cardinality, Set}; + use zfc::{BoundedCardinality, Cardinality, Set}; #[derive(PartialEq, Eq)] struct ClosedInterval { min: usize, @@ -861,8 +865,15 @@ mod tests { } impl Set for ClosedInterval { type Elem = usize; - fn cardinality(&self) -> Cardinality { - Cardinality::Finite(BigUint::from(self.max - self.min) + BigUint::from(1usize)) + fn bounded_cardinality(&self) -> BoundedCardinality { + BoundedCardinality::from_biguint_exact( + BigUint::from(self.max - self.min) + BigUint::from(1usize), + ) + } + fn cardinality(&self) -> Option<Cardinality> { + Some(Cardinality::Finite( + BigUint::from(self.max - self.min) + BigUint::from(1usize), + )) } fn contains<Q>(&self, elem: &Q) -> bool where