normal_form/
set.rs

1mod r#usize;
2
3#[allow(clippy::len_without_is_empty)]
4/// Ordered set.
5pub trait Set {
6	/// Type of the items of the set.
7	type Item: Clone + Ord;
8
9	/// Map type, binding each item of the graph to a value `V`.
10	///
11	/// ## Example
12	///
13	/// `Vec<V>`.
14	type Map<V>: Map<Self::Item, V>;
15
16	/// Items iterator.
17	type Iter<'a>: 'a + Iterator<Item = Self::Item>
18	where
19		Self: 'a;
20
21	/// The number of elements in the set.
22	fn len(&self) -> usize;
23
24	/// Returns an iterator over the items of the set.
25	fn iter(&self) -> Self::Iter<'_>;
26
27	fn map<V: Clone, F>(&self, f: F) -> Self::Map<V>
28	where
29		F: Fn(&Self::Item) -> V;
30}
31
32pub trait Map<K, T> {
33	fn len(&self) -> usize;
34
35	fn is_empty(&self) -> bool {
36		self.len() == 0
37	}
38
39	fn get(&self, key: &K) -> Option<&T>;
40
41	fn set(&mut self, key: &K, value: T);
42
43	fn map<F>(&mut self, f: F)
44	where
45		F: Fn(&K, T) -> T;
46}