frozen_collections_core/sets/
sparse_scalar_lookup_set.rs

1use crate::maps::SparseScalarLookupMap;
2use crate::sets::decl_macros::{
3    bitand_fn, bitor_fn, bitxor_fn, debug_fn, get_fn, into_iter_fn, into_iter_ref_fn,
4    partial_eq_fn, set_iteration_funcs, sub_fn,
5};
6use crate::sets::{IntoIter, Iter};
7use crate::traits::{Len, MapIteration, MapQuery, Scalar, Set, SetIteration, SetOps, SetQuery};
8use core::fmt::Debug;
9use core::hash::Hash;
10use core::ops::{BitAnd, BitOr, BitXor, Sub};
11
12#[cfg(feature = "serde")]
13use {
14    crate::sets::decl_macros::serialize_fn,
15    serde::ser::SerializeSeq,
16    serde::{Serialize, Serializer},
17};
18
19/// A set whose values are a sparse range of values from a scalar.
20///
21#[doc = include_str!("../doc_snippets/private_api_warning.md")]
22#[doc = include_str!("../doc_snippets/about.md")]
23///
24#[derive(Clone)]
25pub struct SparseScalarLookupSet<T> {
26    map: SparseScalarLookupMap<T, ()>,
27}
28
29impl<T> SparseScalarLookupSet<T>
30where
31    T: Scalar,
32{
33    /// Creates a frozen set.
34    ///
35    /// # Errors
36    ///
37    /// Fails if the number of entries in the vector, after deduplication, exceeds the
38    /// magnitude of the collection as specified by the `CM` generic argument.
39    #[must_use]
40    pub const fn new(map: SparseScalarLookupMap<T, ()>) -> Self {
41        Self { map }
42    }
43}
44
45impl<T> Default for SparseScalarLookupSet<T>
46where
47    T: Scalar,
48{
49    fn default() -> Self {
50        Self {
51            map: SparseScalarLookupMap::default(),
52        }
53    }
54}
55
56impl<T> Set<T, T> for SparseScalarLookupSet<T> where T: Scalar {}
57
58impl<T> SetQuery<T, T> for SparseScalarLookupSet<T>
59where
60    T: Scalar,
61{
62    get_fn!("Scalar");
63}
64
65impl<T> SetIteration<T> for SparseScalarLookupSet<T> {
66    type Iterator<'a>
67        = Iter<'a, T>
68    where
69        T: 'a;
70
71    set_iteration_funcs!();
72}
73
74impl<T> Len for SparseScalarLookupSet<T> {
75    fn len(&self) -> usize {
76        self.map.len()
77    }
78}
79
80impl<T, ST> BitOr<&ST> for &SparseScalarLookupSet<T>
81where
82    T: Scalar + Hash,
83    ST: Set<T>,
84{
85    bitor_fn!();
86}
87
88impl<T, ST> BitAnd<&ST> for &SparseScalarLookupSet<T>
89where
90    T: Scalar + Hash,
91    ST: Set<T>,
92{
93    bitand_fn!();
94}
95
96impl<T, ST> BitXor<&ST> for &SparseScalarLookupSet<T>
97where
98    T: Scalar + Hash,
99    ST: Set<T>,
100{
101    bitxor_fn!();
102}
103
104impl<T, ST> Sub<&ST> for &SparseScalarLookupSet<T>
105where
106    T: Scalar + Hash,
107    ST: Set<T>,
108{
109    sub_fn!();
110}
111
112impl<T> IntoIterator for SparseScalarLookupSet<T> {
113    into_iter_fn!();
114}
115
116impl<'a, T> IntoIterator for &'a SparseScalarLookupSet<T> {
117    into_iter_ref_fn!();
118}
119
120impl<T, ST> PartialEq<ST> for SparseScalarLookupSet<T>
121where
122    T: Scalar,
123    ST: Set<T>,
124{
125    partial_eq_fn!();
126}
127
128impl<T> Eq for SparseScalarLookupSet<T> where T: Scalar {}
129
130impl<T> Debug for SparseScalarLookupSet<T>
131where
132    T: Debug,
133{
134    debug_fn!();
135}
136
137#[cfg(feature = "serde")]
138impl<T> Serialize for SparseScalarLookupSet<T>
139where
140    T: Serialize,
141{
142    serialize_fn!();
143}