🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

im-rc

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

im-rc - cargo Package Compare versions

Comparing version
12.3.4
to
13.0.0
+3
-3
Cargo.toml

@@ -6,3 +6,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO

# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g. crates.io) dependencies
# to registry (e.g., crates.io) dependencies
#

@@ -17,3 +17,3 @@ # If you believe there's an error in this file please file an

name = "im-rc"
version = "12.3.4"
version = "13.0.0"
authors = ["Bodil Stokke <bodil@bodil.org>"]

@@ -49,3 +49,3 @@ build = "./build.rs"

[dependencies.sized-chunks]
version = "0.1.2"
version = "0.3.0"

@@ -52,0 +52,0 @@ [dependencies.typenum]

@@ -9,2 +9,37 @@ # Changelog

## [13.0.0] - 2019-05-18
The minimum supported Rust version is now 1.34.0.
### Changed
- `im::iter::unfold` now gives you the owned state value rather than an
immutable reference to it, which makes it a little more useful.
### Removed
- The deprecated `singleton` constructors have been removed. Please use `unit`
instead.
- The deprecated methods `Vector::chunks` and `Vector::chunks_mut` have been
removed in favour of `Vector::leaves` and `Vector::leaves_mut` respectively.
(#50)
- The deprecated reference to [`sized-chunks`](https://crates.io/crates/sized-chunks)
has been removed. If you need it, please use the `sized-chunks` crate directly.
- `im::iter::unfold_mut` has been removed, as there's no meaningful difference
between it and rust-std 1.34.0's `std::iter::from_fn` with a captured state
variable.
### Fixed
- `Vector` now uses
[`sized_chunks::InlineArray`](https://docs.rs/sized-chunks/0.3.0/sized_chunks/inline_array/struct.InlineArray.html)
instead of an `Empty` enum case to avoid allocation at very small sizes,
letting you store a handful of elements on the stack before needing to grow
into a full chunk. This has a beneficial effect on performance as well, as
there's no pointer into the heap to dereference, making it faster than
`std::vec::Vec` in this configuration.
- Some complexity timings have been added and corrected. (#87)
- `OrdSet::is_subset(&self, other)` now returns immediately when `self` is
larger than `other` and thus could not possibly be a subset of it. (#87)
## [12.3.4] - 2019-04-08

@@ -11,0 +46,0 @@

@@ -135,14 +135,2 @@ // This Source Code Form is subject to the terms of the Mozilla Public

///
/// This method has been deprecated; use [`unit`][unit] instead.
///
/// [unit]: #method.unit
#[inline]
#[must_use]
#[deprecated(since = "12.3.0", note = "renamed to `unit` for consistency")]
pub fn singleton(k: K, v: V) -> HashMap<K, V> {
Self::unit(k, v)
}
/// Construct a hash map with a single mapping.
///
/// # Examples

@@ -994,5 +982,8 @@ ///

/// Construct the difference between two maps by discarding keys
/// Construct the symmetric difference between two maps by discarding keys
/// which occur in both maps.
///
/// This is an alias for the
/// [`symmetric_difference`][symmetric_difference] method.
///
/// Time: O(n log n)

@@ -1015,22 +1006,65 @@ ///

pub fn difference(self, other: Self) -> Self {
self.difference_with_key(other, |_, _, _| None)
self.symmetric_difference(other)
}
/// Construct the difference between two maps by using a function
/// Construct the symmetric difference between two maps by discarding keys
/// which occur in both maps.
///
/// Time: O(n log n)
///
/// # Examples
///
/// ```
/// # #[macro_use] extern crate im_rc as im;
/// # use im::hashmap::HashMap;
/// # fn main() {
/// let map1 = hashmap!{1 => 1, 3 => 4};
/// let map2 = hashmap!{2 => 2, 3 => 5};
/// let expected = hashmap!{1 => 1, 2 => 2};
/// assert_eq!(expected, map1.symmetric_difference(map2));
/// # }
/// ```
#[inline]
#[must_use]
pub fn symmetric_difference(self, other: Self) -> Self {
self.symmetric_difference_with_key(other, |_, _, _| None)
}
/// Construct the symmetric difference between two maps by using a function
/// to decide what to do if a key occurs in both.
///
/// This is an alias for the
/// [`symmetric_difference_with`][symmetric_difference_with] method.
///
/// Time: O(n log n)
#[inline]
#[must_use]
pub fn difference_with<F>(self, other: Self, mut f: F) -> Self
pub fn difference_with<F>(self, other: Self, f: F) -> Self
where
F: FnMut(V, V) -> Option<V>,
{
self.difference_with_key(other, |_, a, b| f(a, b))
self.symmetric_difference_with(other, f)
}
/// Construct the difference between two maps by using a function
/// Construct the symmetric difference between two maps by using a function
/// to decide what to do if a key occurs in both.
///
/// Time: O(n log n)
#[inline]
#[must_use]
pub fn symmetric_difference_with<F>(self, other: Self, mut f: F) -> Self
where
F: FnMut(V, V) -> Option<V>,
{
self.symmetric_difference_with_key(other, |_, a, b| f(a, b))
}
/// Construct the symmetric difference between two maps by using a function
/// to decide what to do if a key occurs in both. The function
/// receives the key as well as both values.
///
/// This is an alias for the
/// [`symmetric_difference_with`_key][symmetric_difference_with_key]
/// method.
///
/// Time: O(n log n)

@@ -1054,6 +1088,35 @@ ///

#[must_use]
pub fn difference_with_key<F>(mut self, other: Self, mut f: F) -> Self
pub fn difference_with_key<F>(self, other: Self, f: F) -> Self
where
F: FnMut(&K, V, V) -> Option<V>,
{
self.symmetric_difference_with_key(other, f)
}
/// Construct the symmetric difference between two maps by using a function
/// to decide what to do if a key occurs in both. The function
/// receives the key as well as both values.
///
/// Time: O(n log n)
///
/// # Examples
///
/// ```
/// # #[macro_use] extern crate im_rc as im;
/// # use im::hashmap::HashMap;
/// # fn main() {
/// let map1 = hashmap!{1 => 1, 3 => 4};
/// let map2 = hashmap!{2 => 2, 3 => 5};
/// let expected = hashmap!{1 => 1, 2 => 2, 3 => 9};
/// assert_eq!(expected, map1.symmetric_difference_with_key(
/// map2,
/// |key, left, right| Some(left + right)
/// ));
/// # }
/// ```
#[must_use]
pub fn symmetric_difference_with_key<F>(mut self, other: Self, mut f: F) -> Self
where
F: FnMut(&K, V, V) -> Option<V>,
{
let mut out = self.new_from();

@@ -1075,2 +1138,28 @@ for (key, right_value) in other {

/// Construct the relative complement between two maps by discarding keys
/// which occur in `other`.
///
/// Time: O(m log n) where m is the size of the other map
///
/// # Examples
///
/// ```
/// # #[macro_use] extern crate im_rc as im;
/// # use im::ordmap::OrdMap;
/// # fn main() {
/// let map1 = ordmap!{1 => 1, 3 => 4};
/// let map2 = ordmap!{2 => 2, 3 => 5};
/// let expected = ordmap!{1 => 1};
/// assert_eq!(expected, map1.relative_complement(map2));
/// # }
/// ```
#[inline]
#[must_use]
pub fn relative_complement(mut self, other: Self) -> Self {
for (key, _) in other {
let _ = self.remove(&key);
}
self
}
/// Construct the intersection of two maps, keeping the values

@@ -1077,0 +1166,0 @@ /// from the current map.

@@ -22,3 +22,3 @@ // This Source Code Form is subject to the terms of the Mozilla Public

//! [std::hash::Hash]: https://doc.rust-lang.org/std/hash/trait.Hash.html
//! [std::collections::hash_map::RandomState]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.h
//! [std::collections::hash_map::RandomState]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html

@@ -93,3 +93,3 @@ use std::borrow::Borrow;

/// [std::hash::Hash]: https://doc.rust-lang.org/std/hash/trait.Hash.html
/// [std::collections::hash_map::RandomState]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.h
/// [std::collections::hash_map::RandomState]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html
pub struct HashSet<A, S = RandomState> {

@@ -142,14 +142,2 @@ hasher: Ref<S>,

///
/// This method has been deprecated; use [`unit`][unit] instead.
///
/// [unit]: #method.unit
#[inline]
#[must_use]
#[deprecated(since = "12.3.0", note = "renamed to `unit` for consistency")]
pub fn singleton(a: A) -> Self {
Self::unit(a)
}
/// Construct a set with a single value.
///
/// # Examples

@@ -505,4 +493,7 @@ ///

/// Construct the difference between two sets.
/// Construct the symmetric difference between two sets.
///
/// This is an alias for the
/// [`symmetric_difference`][symmetric_difference] method.
///
/// Time: O(n log n)

@@ -523,3 +514,24 @@ ///

#[must_use]
pub fn difference(mut self, other: Self) -> Self {
pub fn difference(self, other: Self) -> Self {
self.symmetric_difference(other)
}
/// Construct the symmetric difference between two sets.
///
/// Time: O(n log n)
///
/// # Examples
///
/// ```
/// # #[macro_use] extern crate im_rc as im;
/// # use im::hashset::HashSet;
/// # fn main() {
/// let set1 = hashset!{1, 2};
/// let set2 = hashset!{2, 3};
/// let expected = hashset!{1, 3};
/// assert_eq!(expected, set1.symmetric_difference(set2));
/// # }
/// ```
#[must_use]
pub fn symmetric_difference(mut self, other: Self) -> Self {
for value in other {

@@ -533,2 +545,27 @@ if self.remove(&value).is_none() {

/// Construct the relative complement between two sets, that is the set
/// of values in `self` that do not occur in `other`.
///
/// Time: O(m log n) where m is the size of the other set
///
/// # Examples
///
/// ```
/// # #[macro_use] extern crate im_rc as im;
/// # use im::ordset::OrdSet;
/// # fn main() {
/// let set1 = ordset!{1, 2};
/// let set2 = ordset!{2, 3};
/// let expected = ordset!{1};
/// assert_eq!(expected, set1.relative_complement(set2));
/// # }
/// ```
#[must_use]
pub fn relative_complement(mut self, other: Self) -> Self {
for value in other {
let _ = self.remove(&value);
}
self
}
/// Construct the intersection of two sets.

@@ -535,0 +572,0 @@ ///

@@ -7,48 +7,9 @@ // This Source Code Form is subject to the terms of the Mozilla Public

pub struct Unfold<F, S> {
f: F,
value: S,
}
impl<F, S, A> Iterator for Unfold<F, S>
where
F: Fn(&S) -> Option<(A, S)>,
{
type Item = A;
fn next(&mut self) -> Option<Self::Item> {
match (self.f)(&self.value) {
None => None,
Some((next, value)) => {
self.value = value;
Some(next)
}
}
}
}
pub struct UnfoldMut<F, S> {
f: F,
value: S,
}
impl<F, S, A> Iterator for UnfoldMut<F, S>
where
F: Fn(&mut S) -> Option<A>,
{
type Item = A;
fn next(&mut self) -> Option<Self::Item> {
(self.f)(&mut self.value)
}
}
/// Create an iterator of values using a function to update a state
/// Create an iterator of values using a function to update an owned state
/// value.
///
/// The function is called with the current state as its argument, and
/// should return an [`Option`][std::option::Option] of a tuple of the
/// next value to yield from the iterator and the updated state. If
/// the function returns [`None`][std::option::Option::None], the
/// iterator ends.
/// The function is called with the current state as its argument, and should
/// return an [`Option`][std::option::Option] of a tuple of the next value to
/// yield from the iterator and the updated state. If the function returns
/// [`None`][std::option::Option::None], the iterator ends.
///

@@ -63,3 +24,3 @@ /// # Examples

/// // Create an infinite stream of numbers, starting at 0.
/// let mut it = unfold(0, |i| Some((*i, *i + 1)));
/// let mut it = unfold(0, |i| Some((i, i + 1)));
///

@@ -75,51 +36,13 @@ /// // Make a list out of its first five elements.

#[must_use]
pub fn unfold<F, S, A>(value: S, f: F) -> Unfold<F, S>
pub fn unfold<F, S, A>(value: S, f: F) -> impl Iterator<Item = A>
where
F: Fn(&S) -> Option<(A, S)>,
F: Fn(S) -> Option<(A, S)>,
{
Unfold { f, value }
let mut value = Some(value);
std::iter::from_fn(move || {
f(value.take().unwrap()).map(|(next, state)| {
value = Some(state);
next
})
})
}
/// Create an iterator of values using a function to mutate a state
/// value.
///
/// The function is called with a mutable reference to the current
/// state as its argument, and should return an
/// [`Option`][std::option::Option] of the next value to yield from
/// the iterator, updating the state as necessary. If the function
/// returns [`None`][std::option::Option::None], the iterator ends.
///
/// This differs from [`unfold`][unfold] in that your update functions
/// will probably be less elegant, but it's easier to deal with state
/// that isn't efficiently cloneable.
///
/// # Examples
/// ```
/// # #[macro_use] extern crate im_rc as im;
/// # use im::iter::unfold_mut;
/// # use im::vector::Vector;
/// # use std::iter::FromIterator;
/// # fn main() {
/// // Create an infinite stream of numbers, starting at 0.
/// let mut it = unfold_mut(0, |i| {
/// let next = *i;
/// *i += 1;
/// Some(next)
/// });
///
/// // Make a list out of its first five elements.
/// let numbers = Vector::from_iter(it.take(5));
/// assert_eq!(numbers, vector![0, 1, 2, 3, 4]);
/// # }
/// ```
///
/// [std::option::Option]: https://doc.rust-lang.org/std/option/enum.Option.html
/// [std::option::Option::None]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
/// [unfold]: ./fn.unfold.html
#[must_use]
pub fn unfold_mut<F, S, A>(value: S, f: F) -> UnfoldMut<F, S>
where
F: Fn(&mut S) -> Option<A>,
{
UnfoldMut { f, value }
}

@@ -367,5 +367,2 @@ // This Source Code Form is subject to the terms of the Mozilla Public

#[deprecated(since = "12.3.1", note = "please use the `sized_chunks` crate instead")]
pub use sized_chunks::sized_chunk as chunk;
pub use crate::hashmap::HashMap;

@@ -372,0 +369,0 @@ pub use crate::hashset::HashSet;

@@ -190,14 +190,2 @@ // This Source Code Form is subject to the terms of the Mozilla Public

///
/// This method has been deprecated; use [`unit`][unit] instead.
///
/// [unit]: #method.unit
#[inline]
#[must_use]
#[deprecated(since = "12.3.0", note = "renamed to `unit` for consistency")]
pub fn singleton(a: A) -> Self {
Self::unit(a)
}
/// Construct a set with a single value.
///
/// # Examples

@@ -298,2 +286,4 @@ ///

/// If the set is empty, returns `None`.
///
/// Time: O(log n)
#[must_use]

@@ -307,2 +297,4 @@ pub fn get_min(&self) -> Option<&A> {

/// If the set is empty, returns `None`.
///
/// Time: O(log n)
#[must_use]

@@ -380,3 +372,3 @@ pub fn get_max(&self) -> Option<&A> {

///
/// Time: O(n log n)
/// Time: O(n log m) where m is the size of the other set
#[must_use]

@@ -387,4 +379,7 @@ pub fn is_subset<RS>(&self, other: RS) -> bool

{
let o = other.borrow();
self.iter().all(|a| o.contains(&a))
let other = other.borrow();
if other.len() < self.len() {
return false;
}
self.iter().all(|a| other.contains(&a))
}

@@ -396,3 +391,3 @@

///
/// Time: O(n log n)
/// Time: O(n log m) where m is the size of the other set
#[must_use]

@@ -601,4 +596,7 @@ pub fn is_proper_subset<RS>(&self, other: RS) -> bool

/// Construct the difference between two sets.
/// Construct the symmetric difference between two sets.
///
/// This is an alias for the
/// [`symmetric_difference`][symmetric_difference] method.
///
/// Time: O(n log n)

@@ -619,3 +617,24 @@ ///

#[must_use]
pub fn difference(mut self, other: Self) -> Self {
pub fn difference(self, other: Self) -> Self {
self.symmetric_difference(other)
}
/// Construct the symmetric difference between two sets.
///
/// Time: O(n log n)
///
/// # Examples
///
/// ```
/// # #[macro_use] extern crate im_rc as im;
/// # use im::ordset::OrdSet;
/// # fn main() {
/// let set1 = ordset!{1, 2};
/// let set2 = ordset!{2, 3};
/// let expected = ordset!{1, 3};
/// assert_eq!(expected, set1.symmetric_difference(set2));
/// # }
/// ```
#[must_use]
pub fn symmetric_difference(mut self, other: Self) -> Self {
for value in other {

@@ -629,2 +648,27 @@ if self.remove(&value).is_none() {

/// Construct the relative complement between two sets, that is the set
/// of values in `self` that do not occur in `other`.
///
/// Time: O(m log n) where m is the size of the other set
///
/// # Examples
///
/// ```
/// # #[macro_use] extern crate im_rc as im;
/// # use im::ordset::OrdSet;
/// # fn main() {
/// let set1 = ordset!{1, 2};
/// let set2 = ordset!{2, 3};
/// let expected = ordset!{1};
/// assert_eq!(expected, set1.relative_complement(set2));
/// # }
/// ```
#[must_use]
pub fn relative_complement(mut self, other: Self) -> Self {
for value in other {
let _ = self.remove(&value);
}
self
}
/// Construct the intersection of two sets.

@@ -853,2 +897,5 @@ ///

/// Advance the iterator and return the next value.
///
/// Time: O(1)*
fn next(&mut self) -> Option<Self::Item> {

@@ -892,2 +939,5 @@ self.it.next().map(Deref::deref)

/// Advance the iterator and return the next value.
///
/// Time: O(1)*
fn next(&mut self) -> Option<Self::Item> {

@@ -922,2 +972,5 @@ self.it.next().map(Deref::deref)

/// Advance the iterator and return the next value.
///
/// Time: O(1)*
fn next(&mut self) -> Option<Self::Item> {

@@ -939,2 +992,5 @@ self.it.next().map(|v| v.0)

/// Advance the iterator and return the next value.
///
/// Time: O(1)*
fn next(&mut self) -> Option<Self::Item> {

@@ -941,0 +997,0 @@ self.it.next().map(|item| match item {

@@ -89,4 +89,2 @@ // This Source Code Form is subject to the terms of the Mozilla Public

#[doc(hidden)]
Empty,
#[doc(hidden)]
Single(&'a [A]),

@@ -106,3 +104,3 @@ #[doc(hidden)]

match vector {
Vector::Empty => Focus::Empty,
Vector::Inline(chunk) => Focus::Single(chunk),
Vector::Single(chunk) => Focus::Single(chunk),

@@ -118,3 +116,2 @@ Vector::Full(tree) => Focus::Full(TreeFocus::new(tree)),

match self {
Focus::Empty => 0,
Focus::Single(chunk) => chunk.len(),

@@ -135,3 +132,2 @@ Focus::Full(tree) => tree.len(),

match self {
Focus::Empty => None,
Focus::Single(chunk) => chunk.get(index),

@@ -159,3 +155,2 @@ Focus::Full(tree) => tree.get(index),

match self {
Focus::Empty => (0..0, &[]),
Focus::Single(chunk) => (0..len, chunk),

@@ -198,3 +193,2 @@ Focus::Full(tree) => tree.get_chunk(index),

match self {
Focus::Empty => Focus::Empty,
Focus::Single(chunk) => Focus::Single(&chunk[r]),

@@ -240,3 +234,2 @@ Focus::Full(tree) => Focus::Full(tree.narrow(r)),

match self {
Focus::Empty => (Focus::Empty, Focus::Empty),
Focus::Single(chunk) => {

@@ -272,3 +265,2 @@ let (left, right) = chunk.split_at(index);

match self {
Focus::Empty => Focus::Empty,
Focus::Single(chunk) => Focus::Single(chunk),

@@ -495,4 +487,2 @@ Focus::Full(tree) => Focus::Full(tree.clone()),

#[doc(hidden)]
Empty,
#[doc(hidden)]
Single(&'a mut [A]),

@@ -510,3 +500,3 @@ #[doc(hidden)]

match vector {
Vector::Empty => FocusMut::Empty,
Vector::Inline(chunk) => FocusMut::Single(chunk),
Vector::Single(chunk) => FocusMut::Single(Ref::make_mut(chunk).as_mut_slice()),

@@ -520,3 +510,2 @@ Vector::Full(tree) => FocusMut::Full(TreeFocusMut::new(tree)),

match self {
FocusMut::Empty => 0,
FocusMut::Single(chunk) => chunk.len(),

@@ -540,3 +529,2 @@ FocusMut::Full(tree) => tree.len(),

match self {
FocusMut::Empty => None,
FocusMut::Single(chunk) => chunk.get_mut(index),

@@ -660,3 +648,2 @@ FocusMut::Full(tree) => tree.get(index),

match self {
FocusMut::Empty => (0..0, &mut []),
FocusMut::Single(chunk) => (0..len, chunk),

@@ -702,3 +689,2 @@ FocusMut::Full(tree) => {

match self {
FocusMut::Empty => FocusMut::Empty,
FocusMut::Single(chunk) => FocusMut::Single(&mut chunk[r]),

@@ -751,3 +737,2 @@ FocusMut::Full(tree) => FocusMut::Full(tree.narrow(r)),

match self {
FocusMut::Empty => (FocusMut::Empty, FocusMut::Empty),
FocusMut::Single(chunk) => {

@@ -767,3 +752,2 @@ let (left, right) = chunk.split_at_mut(index);

match self {
FocusMut::Empty => Focus::Empty,
FocusMut::Single(chunk) => Focus::Single(chunk),

@@ -770,0 +754,0 @@ FocusMut::Full(mut tree) => Focus::Full(TreeFocus {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display