micromap_rawl/set/mod.rs
1mod clone;
2mod ctors;
3mod debug;
4mod display;
5mod drain;
6mod eq;
7mod from;
8mod functions;
9mod iterators;
10
11use crate::Map;
12
13/// A faster alternative of [`std::collections::HashSet`].
14///
15/// For example, this is how you make a set, which is allocated on stack and is capable of storing
16/// up to eight key-values pairs:
17///
18/// ```
19/// let mut m : micromap_rawl::Set<u64, 8> = micromap_rawl::Set::new();
20/// m.insert(1);
21/// m.insert(2);
22/// # #[cfg(std)]
23/// assert_eq!(2, m.len());
24/// ```
25///
26/// It is faster because it doesn't use a hash function at all. It simply keeps
27/// all pairs in an array and when it's necessary to find a value, it goes through
28/// all pairs comparing the needle with each pair available. Also it is faster
29/// because it doesn't use heap. When a [`Set`] is being created, it allocates the necessary
30/// space on stack. That's why the maximum size of the set must be provided in
31/// compile time.
32///
33/// It is also faster because it doesn't grow in size. When a [`Set`] is created,
34/// its size is fixed on stack. If an attempt is made to insert too many keys
35/// into it, it simply panics. Moreover, in the "release" mode it doesn't panic,
36/// but its behaviour is undefined. In the "release" mode all boundary checks
37/// are disabled, for the sake of higher performance.
38#[repr(transparent)]
39pub struct Set<T: PartialEq, const N: usize> {
40 map: Map<T, (), N>,
41}
42
43/// Iterator over the [`Set`].
44#[repr(transparent)]
45#[allow(clippy::module_name_repetitions)]
46pub struct SetIter<'a, T> {
47 iter: crate::Keys<'a, T, ()>,
48}
49
50/// Into-iterator over the [`Set`].
51#[repr(transparent)]
52#[allow(clippy::module_name_repetitions)]
53pub struct SetIntoIter<T: PartialEq, const N: usize> {
54 iter: crate::IntoKeys<T, (), N>,
55}
56
57#[repr(transparent)]
58#[allow(clippy::module_name_repetitions)]
59pub struct SetDrain<'a, T: PartialEq> {
60 iter: crate::Drain<'a, T, ()>,
61}