From 4f9fe856a25ab29345b90e7725509e9ee38a37be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:41 +0200 Subject: Adding upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/zerovec/src/map2d/borrowed.rs | 9 ++--- vendor/zerovec/src/map2d/cursor.rs | 70 +++++++++++++++++++++++++++++++----- vendor/zerovec/src/map2d/map.rs | 12 +++---- vendor/zerovec/src/map2d/serde.rs | 8 ++--- 4 files changed, 73 insertions(+), 26 deletions(-) (limited to 'vendor/zerovec/src/map2d') diff --git a/vendor/zerovec/src/map2d/borrowed.rs b/vendor/zerovec/src/map2d/borrowed.rs index d9972fae9..209da299b 100644 --- a/vendor/zerovec/src/map2d/borrowed.rs +++ b/vendor/zerovec/src/map2d/borrowed.rs @@ -199,11 +199,6 @@ where /// assert_eq!(borrowed.get_2d(&2, "one"), Some("bar")); /// assert_eq!(borrowed.get_2d(&2, "two"), Some("baz")); /// assert_eq!(borrowed.get_2d(&3, "three"), None); - /// - /// let borrow = borrowed.get_2d(&1, "one"); - /// drop(borrowed); - /// // still exists after the ZeroMap2dBorrowed has been dropped - /// assert_eq!(borrow, Some("foo")); /// ``` pub fn get_2d(&self, key0: &K0, key1: &K1) -> Option<&'a V::GetType> { self.get0(key0)?.get1(key1) @@ -270,8 +265,8 @@ where /// map.insert(&1, "one", "foo"); /// map.insert(&2, "two", "bar"); /// let borrowed = map.as_borrowed(); - /// assert_eq!(borrowed.contains_key0(&1), true); - /// assert_eq!(borrowed.contains_key0(&3), false); + /// assert!(borrowed.contains_key0(&1)); + /// assert!(!borrowed.contains_key0(&3)); /// ``` pub fn contains_key0(&self, key0: &K0) -> bool { self.keys0.zvl_binary_search(key0).is_ok() diff --git a/vendor/zerovec/src/map2d/cursor.rs b/vendor/zerovec/src/map2d/cursor.rs index 0654ee794..4802187be 100644 --- a/vendor/zerovec/src/map2d/cursor.rs +++ b/vendor/zerovec/src/map2d/cursor.rs @@ -92,7 +92,9 @@ where self.keys0.zvl_get(self.key0_index).unwrap() } - /// Borrow an ordered iterator over keys1 for a particular key0. + /// Borrow an ordered iterator over keys1 and values for a particular key0. + /// + /// To get the values as copy types, see [`Self::iter1_copied`]. /// /// For an example, see [`ZeroMap2d::iter0()`]. pub fn iter1( @@ -150,6 +152,64 @@ where } } +impl<'l, 'a, K0, K1, V> ZeroMap2dCursor<'l, 'a, K0, K1, V> +where + K0: ZeroMapKV<'a>, + K1: ZeroMapKV<'a>, + V: ZeroMapKV<'a>, + K0: ?Sized, + K1: ?Sized, + V: Copy, +{ + /// Borrow an ordered iterator over keys1 and values for a particular key0. + /// + /// The values are returned as copy types. + /// + /// # Examples + /// + /// ``` + /// use zerovec::ZeroMap2d; + /// + /// let zm2d: ZeroMap2d = [ + /// ("a", 0u8, 1usize), + /// ("b", 1u8, 1000usize), + /// ("b", 2u8, 2000usize), + /// ] + /// .into_iter() + /// .collect(); + /// + /// let mut total_value = 0; + /// + /// for cursor in zm2d.iter0() { + /// for (_, value) in cursor.iter1_copied() { + /// total_value += value; + /// } + /// } + /// + /// assert_eq!(total_value, 3001); + /// ``` + pub fn iter1_copied( + &self, + ) -> impl Iterator>::GetType, V)> + '_ { + let range = self.get_range(); + #[allow(clippy::unwrap_used)] // `self.get_range()` returns a valid range + range.map(move |idx| { + ( + self.keys1.zvl_get(idx).unwrap(), + self.get1_copied_at(idx).unwrap(), + ) + }) + } + + fn get1_copied_at(&self, index: usize) -> Option { + let ule = self.values.zvl_get(index)?; + let mut result = Option::::None; + V::Container::zvl_get_as_t(ule, |v| result.replace(*v)); + #[allow(clippy::unwrap_used)] // `zvl_get_as_t` guarantees that the callback is invoked + Some(result.unwrap()) + } +} + impl<'l, 'a, K0, K1, V> ZeroMap2dCursor<'l, 'a, K0, K1, V> where K0: ZeroMapKV<'a>, @@ -253,14 +313,6 @@ where let key1_index = self.get_key1_index_by(predicate)?; self.get1_copied_at(key1_index) } - - fn get1_copied_at(&self, index: usize) -> Option { - let ule = self.values.zvl_get(index)?; - let mut result = Option::::None; - V::Container::zvl_get_as_t(ule, |v| result.replace(*v)); - #[allow(clippy::unwrap_used)] // `zvl_get_as_t` guarantees that the callback is invoked - Some(result.unwrap()) - } } // We can't use the default PartialEq because ZeroMap2d is invariant diff --git a/vendor/zerovec/src/map2d/map.rs b/vendor/zerovec/src/map2d/map.rs index ab6eded4e..e6545dfa5 100644 --- a/vendor/zerovec/src/map2d/map.rs +++ b/vendor/zerovec/src/map2d/map.rs @@ -534,8 +534,8 @@ where /// let mut map = ZeroMap2d::new(); /// map.insert(&1, "one", "foo"); /// map.insert(&2, "two", "bar"); - /// assert_eq!(map.contains_key0(&1), true); - /// assert_eq!(map.contains_key0(&3), false); + /// assert!(map.contains_key0(&1)); + /// assert!(!map.contains_key0(&3)); /// ``` pub fn contains_key0(&self, key0: &K0) -> bool { self.keys0.zvl_binary_search(key0).is_ok() @@ -814,13 +814,13 @@ mod test { // Remove some elements let result = zm2d.remove(&3, "ccc"); // first element - assert_eq!(result, Some(String::from("CCC").into_boxed_str())); + assert_eq!(result.as_deref(), Some("CCC")); let result = zm2d.remove(&3, "mmm"); // middle element - assert_eq!(result, Some(String::from("MM0").into_boxed_str())); + assert_eq!(result.as_deref(), Some("MM0")); let result = zm2d.remove(&5, "ddd"); // singleton K0 - assert_eq!(result, Some(String::from("DD1").into_boxed_str())); + assert_eq!(result.as_deref(), Some("DD1")); let result = zm2d.remove(&9, "yyy"); // last element - assert_eq!(result, Some(String::from("YYY").into_boxed_str())); + assert_eq!(result.as_deref(), Some("YYY")); assert_eq!(format!("{:?}", zm2d), "ZeroMap2d { keys0: ZeroVec([3, 6, 7]), joiner: ZeroVec([1, 4, 7]), keys1: [\"eee\", \"ddd\", \"mmm\", \"nnn\", \"ddd\", \"eee\", \"www\"], values: [\"EEE\", \"DD3\", \"MM1\", \"NNN\", \"DD2\", \"EEE\", \"WWW\"] }"); } diff --git a/vendor/zerovec/src/map2d/serde.rs b/vendor/zerovec/src/map2d/serde.rs index f8b5f147b..b5e913654 100644 --- a/vendor/zerovec/src/map2d/serde.rs +++ b/vendor/zerovec/src/map2d/serde.rs @@ -12,7 +12,7 @@ use serde::de::{self, Deserialize, Deserializer, MapAccess, Visitor}; #[cfg(feature = "serde")] use serde::ser::{Serialize, SerializeMap, Serializer}; -/// This impl can be made available by enabling the optional `serde` feature of the `zerovec` crate +/// This impl requires enabling the optional `serde` Cargo feature of the `zerovec` crate #[cfg(feature = "serde")] impl<'a, K0, K1, V> Serialize for ZeroMap2d<'a, K0, K1, V> where @@ -75,7 +75,7 @@ where } } -/// This impl can be made available by enabling the optional `serde` feature of the `zerovec` crate +/// This impl requires enabling the optional `serde` Cargo feature of the `zerovec` crate #[cfg(feature = "serde")] impl<'a, K0, K1, V> Serialize for ZeroMap2dBorrowed<'a, K0, K1, V> where @@ -220,7 +220,7 @@ where } } -/// This impl can be made available by enabling the optional `serde` feature of the `zerovec` crate +/// This impl requires enabling the optional `serde` Cargo feature of the `zerovec` crate impl<'de, 'a, K0, K1, V> Deserialize<'de> for ZeroMap2d<'a, K0, K1, V> where K0: ZeroMapKV<'a> + Ord + ?Sized, @@ -287,7 +287,7 @@ where } } -/// This impl can be made available by enabling the optional `serde` feature of the `zerovec` crate +/// This impl requires enabling the optional `serde` Cargo feature of the `zerovec` crate impl<'de, 'a, K0, K1, V> Deserialize<'de> for ZeroMap2dBorrowed<'a, K0, K1, V> where K0: ZeroMapKV<'a> + Ord + ?Sized, -- cgit v1.2.3