Crates.io | utote |
lib.rs | utote |
version | 0.6.1 |
source | src |
created_at | 2021-01-25 18:53:35.743015 |
updated_at | 2023-09-29 15:19:28.252881 |
description | Stack allocated uint multiset, with optional SIMD implementations. |
homepage | https://github.com/Maracoo/utote |
repository | https://github.com/Maracoo/utote |
max_upload_size | |
id | 346581 |
size | 137,132 |
High performance, stack allocated uint multiset implementation on rust stable, with optional simd implementations available using rust nightly.
minimum supported rust version: 1.51
use utote::Multiset;
// A multiset of 5 elements, which can be counted up to u8::MAX
let mut multiset = Multiset::from([0u8, 3, 4, 0, 5]);
assert_eq!(multiset.total(), 12);
let equivalent_multiset = Multiset::<u8, 5>::from([0, 3, 4, 0, 5]);
assert_eq!(multiset, equivalent_multiset);
multiset.insert(2, 6);
assert_eq!(multiset, Multiset::from([0, 3, 6, 0, 5]));
for elem in multiset.iter() {
println!("{}", elem);
}
assert_eq!(multiset.contains(0), false);
assert_eq!(multiset.contains(1), true);
Some common set-like operations:
use utote::Multiset;
let ms_sub: Multiset<u32, 3> = Multiset::from([0, 1, 1]);
let ms_super = Multiset::from([1, 1, 2]);
assert_eq!(ms_sub.is_subset(&ms_super), true);
assert_eq!(ms_sub.union(&ms_super), Multiset::from([1, 1, 2]));
assert_eq!(ms_super.is_proper_superset(&ms_sub), true);
// Any multiset where all counters are zero is equivalent to
// the empty multiset.
let empty: Multiset<u64, 2> = Multiset::from([0, 0]);
assert_eq!(empty, Multiset::empty());
The Utote Multiset has a single generic API but multiple equivalent scalar and simd implementations of various functions where the use of simd can enhance performance. The simd functionality is nightly only, while the scalar versions can be used on stable.
The nightly only simd implementation uses packed_simd and the unstable
features: const_generics and const_evaluatable_checked (all behind the
feature flag "simd"
). packed_simd
was chosen over alternatives due to its
simplicity and based on the assumption that when std::simd is stabilised it
will look similar in API structure to packed_simd
as it is now.
Once const generics and portable simd support hit stable this crate will also
become fully stable. Until these features are stabilised the version of Utote
will stay below 1.0.0
.
Since multisets are essentially collections of counters + some useful methods
on those counters, and to keep things simple, implementations are only provided
for uint
types. The current Multiset is thus quite low level, perhaps better
serving as a backend for a higher level multiset that works for any given type.
Although it would be simple to implement Deref<[T]>
for Multiset I decided
against this for two reasons. Firstly to avoid suggestively exposing methods in
the API for Multiset which could sort the counts. Since the order of the counts
is intrinsic to the implementation working I wanted to avoid any confusion that
this would be appropriate. Second, as most of the functional methods for
Multiset will eventually be implemented on slice and then used from different
multiset varieties implmenting deref to slice could cause confusion in the
code.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
The implementations in this crate are inspired by generic-array, nalgebra and simba.
Multiset::argmax
=> Multiset::elem_count_max
Multiset::argmin
=> Multiset::elem_count_min
Multiset::imax
=> Multiset::elem_max
Multiset::imin
=> Multiset::elem_min
Multiset::max
=> Multiset::count_max
Multiset::min
=> Multiset::count_min
PartialOrd
impl uses most efficient methodFrom
mut Multiset
refis_any_lesser
& is_any_greater
SmallRng
usesconst
constructors to enable stable generic interfaceRem
opsFrom
implementationsFromIterator
and IntoIterator
impl coverageIndex
and IndexMut
implementationsdifference
symmetric_difference
from_elements
is_disjoint
get_mut
get_unchecked_mut
AVX2
AVX
SSE4.2
empty
& repeat
constructors constchoose_random
rand
dependency optionalStdRng
to SmallRng