pub struct SubsetMap<E, P> { /* private fields */ }
Expand description
A map like data structure where the keys are subsets made of combinations of the original sets.
Implementations§
Source§impl<E, P> SubsetMap<E, P>where
E: Clone,
impl<E, P> SubsetMap<E, P>where
E: Clone,
Sourcepub fn new<F>(elements: &[E], init: F) -> SubsetMap<E, P>
pub fn new<F>(elements: &[E], init: F) -> SubsetMap<E, P>
Creates a new instance where the payloads are initialized with a closure that is passed the current subset of elements.
This function assigns values to those combinations where
the given closure init
returns Some
.
§Example
use subset_map::*;
let subset_map = SubsetMap::new(&[1, 2], |x| {
let sum = x.iter().sum::<i32>();
if sum == 1 {
None
} else {
Some(sum)
}
});
assert_eq!(subset_map.get(&[1]), None);
assert_eq!(subset_map.get(&[2]), Some(&2));
assert_eq!(subset_map.get(&[1, 2]), Some(&3));
assert_eq!(subset_map.get(&[]), None);
assert_eq!(subset_map.get(&[2, 1]), None);
assert_eq!(subset_map.get(&[0]), None);
assert_eq!(subset_map.get(&[0, 1]), None);
Sourcepub fn fill<F>(elements: &[E], init: F) -> SubsetMap<E, P>
pub fn fill<F>(elements: &[E], init: F) -> SubsetMap<E, P>
Creates a new instance where the payloads are initialized with a closure that is passed the current subset of elements.
This fuction will assign an element to each subset.
§Example
use subset_map::*;
let subset_map = SubsetMap::fill(&[1, 2], |x| x.iter().sum::<i32>());
assert_eq!(subset_map.get(&[1]), Some(&1));
assert_eq!(subset_map.get(&[2]), Some(&2));
assert_eq!(subset_map.get(&[1, 2]), Some(&3));
assert_eq!(subset_map.get(&[]), None);
assert_eq!(subset_map.get(&[2, 1]), None);
assert_eq!(subset_map.get(&[0]), None);
assert_eq!(subset_map.get(&[0, 1]), None);
Examples found in repository?
More examples
6fn main() {
7 let elements: Vec<_> = (0..17).collect();
8 let start = Instant::now();
9
10 let mut n = 0;
11 let map = SubsetMap::fill(&elements, |_x| {
12 n += 1;
13 n
14 });
15
16 println!(
17 "[CREATE_SIMPLE]: Combinations: {}(Size: {}) -> Time: {:?}",
18 n,
19 map.size(),
20 start.elapsed()
21 );
22
23 drop(map);
24
25 let start = Instant::now();
26
27 let mut n = 0usize;
28 let mut combinations = Vec::new();
29 let map = SubsetMap::fill(&elements, |x| {
30 combinations.push(x.to_vec());
31 n += 1;
32 n
33 });
34
35 println!(
36 "[CREATE_FOR_QUERY]: Combinations: {}(Size: {}) -> Time: {:?}",
37 n,
38 map.size(),
39 start.elapsed()
40 );
41
42 let start = Instant::now();
43
44 let mut n = 0usize;
45 for combination in combinations {
46 if let Some(_p) = map.get(&combination) {
47 n += 1;
48 }
49 }
50
51 println!(
52 "[GET]: Combinations: {} -> Time: {:?} {}",
53 map.size(),
54 start.elapsed(),
55 n
56 );
57
58 drop(map);
59
60 let mut n = 0usize;
61 let mut combinations = Vec::new();
62 let map = SubsetMap::fill(&elements, |x| {
63 combinations.push(x.to_vec());
64 n += 1;
65 n
66 });
67
68 let start = Instant::now();
69
70 let mut n = 0usize;
71 for combination in combinations {
72 if let LookupResult::Perfect(Some(_p)) = map.lookup(&combination) {
73 n += 1;
74 }
75 }
76
77 println!(
78 "[LOOKUP]: Combinations: {} -> Time: {:?} {}",
79 map.size(),
80 start.elapsed(),
81 n
82 );
83
84 drop(map);
85
86 let mut n = 0usize;
87 let mut combinations = Vec::new();
88 let map = SubsetMap::fill(&elements, |x| {
89 combinations.push(x.to_vec());
90 n += 1;
91 n
92 });
93
94 let start = Instant::now();
95
96 let mut n = 0usize;
97 for combination in combinations {
98 if let FindResult::Perfect(_) = map.find(&combination) {
99 n += 1;
100 }
101 }
102
103 println!(
104 "[FIND]: Combinations: {} -> Time: {:?} {}",
105 map.size(),
106 start.elapsed(),
107 n
108 );
109}
Sourcepub fn init<F, X>(elements: &[E], init: F) -> Result<SubsetMap<E, P>, X>
pub fn init<F, X>(elements: &[E], init: F) -> Result<SubsetMap<E, P>, X>
Initializes the SubsetMap
with a closure that can fail.
This function initializes all those subsets with the returned payloads
where the init
closure returned an Result::Ok(Option::Some)
given that all calls on the closure returned Result::Ok
.
Failure of the init
closure will result in a failure
of the whole initialization process.
§Example
The whole initialization process fails.
use subset_map::*;
let subset_map = SubsetMap::init(&[1, 2], |x| {
let sum = x.iter().sum::<i32>();
if sum == 1 {
Ok(Some(sum))
} else if sum == 2 {
Ok(None)
} else {
Err("bang!")
}
});
assert_eq!(subset_map, Err("bang!"));
Sourcepub fn init_filled<F, X>(elements: &[E], init: F) -> Result<SubsetMap<E, P>, X>
pub fn init_filled<F, X>(elements: &[E], init: F) -> Result<SubsetMap<E, P>, X>
Initializes the SubsetMap
with a closure that can fail.
This function initializes all subsets with the returned payloads
given that all calls on the closure returned Result::Ok
.
Failure of the init
closure will result in a failure
of the whole initialization process.
§Example
use subset_map::*;
let subset_map = SubsetMap::init_filled(&[1, 2], |x| {
let sum = x.iter().sum::<i32>();
if sum != 3 {
Ok(sum)
} else {
Err("bang!")
}
});
assert_eq!(subset_map, Err("bang!"));
Sourcepub fn with_value<F>(elements: &[E], init: F) -> SubsetMap<E, P>where
F: FnMut() -> P,
pub fn with_value<F>(elements: &[E], init: F) -> SubsetMap<E, P>where
F: FnMut() -> P,
Creates a new instance where the payloads are all initialized with the same value.
§Example
use subset_map::*;
let subset_map = SubsetMap::with_value(&[1, 2], || 42);
assert_eq!(subset_map.get(&[1]), Some(&42));
assert_eq!(subset_map.get(&[2]), Some(&42));
assert_eq!(subset_map.get(&[1, 2]), Some(&42));
assert_eq!(subset_map.get(&[]), None);
assert_eq!(subset_map.get(&[2, 1]), None);
assert_eq!(subset_map.get(&[0]), None);
assert_eq!(subset_map.get(&[0, 1]), None);
Sourcepub fn with_default(elements: &[E]) -> SubsetMap<E, P>where
P: Default,
pub fn with_default(elements: &[E]) -> SubsetMap<E, P>where
P: Default,
Creates a new instance where the payloads are all initialized
with the Default::default()
value of the payload type.
Creates a new instance where the payloads are all initialized
with the same value.
§Example
use subset_map::*;
let subset_map = SubsetMap::with_default(&[1, 2]);
assert_eq!(subset_map.get(&[1]), Some(&0));
assert_eq!(subset_map.get(&[2]), Some(&0));
assert_eq!(subset_map.get(&[1, 2]), Some(&0));
assert_eq!(subset_map.get(&[]), None);
assert_eq!(subset_map.get(&[2, 1]), None);
assert_eq!(subset_map.get(&[0]), None);
assert_eq!(subset_map.get(&[0, 1]), None);
Sourcepub fn get<'a>(&'a self, subset: &[E]) -> Option<&'a P>where
E: Eq,
pub fn get<'a>(&'a self, subset: &[E]) -> Option<&'a P>where
E: Eq,
Gets a payload by the given subset.
Only “perfect” matches on subset
are returned.
The function returns None
regardless of whether
subset
was part of the map or there was no payload
assigned to the given subset.
use subset_map::*;
let subset_map = SubsetMap::new(&[1, 2, 3], |x| {
let payload = x.iter().cloned().collect::<Vec<_>>();
if payload.len() == 1 {
None
} else {
Some(payload)
}
});
assert_eq!(subset_map.get(&[1]), None);
assert_eq!(subset_map.get(&[2]), None);
assert_eq!(subset_map.get(&[3]), None);
assert_eq!(subset_map.get(&[1, 2]), Some(&vec![1, 2]));
assert_eq!(subset_map.get(&[2, 3]), Some(&vec![2, 3]));
assert_eq!(subset_map.get(&[1, 3]), Some(&vec![1, 3]));
assert_eq!(subset_map.get(&[1, 2, 3]), Some(&vec![1, 2, 3]));
assert_eq!(subset_map.get(&[]), None);
assert_eq!(subset_map.get(&[7]), None);
assert_eq!(subset_map.get(&[3, 2, 1]), None);
assert_eq!(subset_map.get(&[1, 3, 2]), None);
assert_eq!(subset_map.get(&[3, 2, 1]), None);
assert_eq!(subset_map.get(&[2, 1]), None);
Examples found in repository?
6fn main() {
7 let elements: Vec<_> = (0..17).collect();
8 let start = Instant::now();
9
10 let mut n = 0;
11 let map = SubsetMap::fill(&elements, |_x| {
12 n += 1;
13 n
14 });
15
16 println!(
17 "[CREATE_SIMPLE]: Combinations: {}(Size: {}) -> Time: {:?}",
18 n,
19 map.size(),
20 start.elapsed()
21 );
22
23 drop(map);
24
25 let start = Instant::now();
26
27 let mut n = 0usize;
28 let mut combinations = Vec::new();
29 let map = SubsetMap::fill(&elements, |x| {
30 combinations.push(x.to_vec());
31 n += 1;
32 n
33 });
34
35 println!(
36 "[CREATE_FOR_QUERY]: Combinations: {}(Size: {}) -> Time: {:?}",
37 n,
38 map.size(),
39 start.elapsed()
40 );
41
42 let start = Instant::now();
43
44 let mut n = 0usize;
45 for combination in combinations {
46 if let Some(_p) = map.get(&combination) {
47 n += 1;
48 }
49 }
50
51 println!(
52 "[GET]: Combinations: {} -> Time: {:?} {}",
53 map.size(),
54 start.elapsed(),
55 n
56 );
57
58 drop(map);
59
60 let mut n = 0usize;
61 let mut combinations = Vec::new();
62 let map = SubsetMap::fill(&elements, |x| {
63 combinations.push(x.to_vec());
64 n += 1;
65 n
66 });
67
68 let start = Instant::now();
69
70 let mut n = 0usize;
71 for combination in combinations {
72 if let LookupResult::Perfect(Some(_p)) = map.lookup(&combination) {
73 n += 1;
74 }
75 }
76
77 println!(
78 "[LOOKUP]: Combinations: {} -> Time: {:?} {}",
79 map.size(),
80 start.elapsed(),
81 n
82 );
83
84 drop(map);
85
86 let mut n = 0usize;
87 let mut combinations = Vec::new();
88 let map = SubsetMap::fill(&elements, |x| {
89 combinations.push(x.to_vec());
90 n += 1;
91 n
92 });
93
94 let start = Instant::now();
95
96 let mut n = 0usize;
97 for combination in combinations {
98 if let FindResult::Perfect(_) = map.find(&combination) {
99 n += 1;
100 }
101 }
102
103 println!(
104 "[FIND]: Combinations: {} -> Time: {:?} {}",
105 map.size(),
106 start.elapsed(),
107 n
108 );
109}
Sourcepub fn get_owned(&self, subset: &[E]) -> Option<P::Owned>
pub fn get_owned(&self, subset: &[E]) -> Option<P::Owned>
Looks up a payload by the given subset and returns the corresponding owned value.
The function returns None
regardless of wether
subset
was part of the map or there was no payload
assigned to the given subset.
Only perfect matches on subset
are returned. See get
.
Sourcepub fn lookup<'a>(&'a self, subset: &[E]) -> LookupResult<'a, E, P>where
E: Eq,
pub fn lookup<'a>(&'a self, subset: &[E]) -> LookupResult<'a, E, P>where
E: Eq,
Looks up a subset and maybe returns the assigned payload.
Elements in subset
that are not part of the initial set are
skipped.
The returned LookupResult
may still contain an optional
payload. None indicates that the subset was matched but
there was no payload for the given subset.
Use this method if you are interested whether there was
a matching subset and then process the maybe present payload.
Otherwise use find
or lookup
.
§Example
use subset_map::*;
let subset_map = SubsetMap::new(&[1u32, 2, 3], |x| {
if x == &[2] {
None
} else {
let payload = x.iter().cloned().collect::<Vec<_>>();
Some(payload)
}
});
let empty: &[u32] = &[];
// A perfect match with a payload:
let match_result = subset_map.lookup(&[1]);
assert_eq!(match_result.payload(), Some(&vec![1]));
assert_eq!(match_result.excluded_elements(), empty);
assert_eq!(match_result.is_match(), true);
assert_eq!(match_result.is_perfect(), true);
assert_eq!(match_result.is_excluded(), false);
// A perfect match that has no payload:
let match_result = subset_map.lookup(&[2]);
assert_eq!(match_result.payload(), None);
assert_eq!(match_result.excluded_elements(), empty);
assert_eq!(match_result.is_match(), true);
assert_eq!(match_result.is_perfect(), true);
assert_eq!(match_result.is_excluded(), false);
// There is no answer at all:
let match_result = subset_map.lookup(&[42]);
assert_eq!(match_result.is_no_match(), true);
assert_eq!(match_result.is_perfect(), false);
assert_eq!(match_result.is_excluded(), false);
assert_eq!(match_result.excluded_elements(), empty);
// A nearby match but that has a payload:
let match_result = subset_map.lookup(&[3,1]);
assert_eq!(match_result.payload(), Some(&vec![3]));
assert_eq!(match_result.excluded_elements(), &[1]);
assert_eq!(match_result.is_perfect(), false);
assert_eq!(match_result.is_excluded(), true);
assert_eq!(match_result.is_match(), true);
Examples found in repository?
6fn main() {
7 let elements: Vec<_> = (0..17).collect();
8 let start = Instant::now();
9
10 let mut n = 0;
11 let map = SubsetMap::fill(&elements, |_x| {
12 n += 1;
13 n
14 });
15
16 println!(
17 "[CREATE_SIMPLE]: Combinations: {}(Size: {}) -> Time: {:?}",
18 n,
19 map.size(),
20 start.elapsed()
21 );
22
23 drop(map);
24
25 let start = Instant::now();
26
27 let mut n = 0usize;
28 let mut combinations = Vec::new();
29 let map = SubsetMap::fill(&elements, |x| {
30 combinations.push(x.to_vec());
31 n += 1;
32 n
33 });
34
35 println!(
36 "[CREATE_FOR_QUERY]: Combinations: {}(Size: {}) -> Time: {:?}",
37 n,
38 map.size(),
39 start.elapsed()
40 );
41
42 let start = Instant::now();
43
44 let mut n = 0usize;
45 for combination in combinations {
46 if let Some(_p) = map.get(&combination) {
47 n += 1;
48 }
49 }
50
51 println!(
52 "[GET]: Combinations: {} -> Time: {:?} {}",
53 map.size(),
54 start.elapsed(),
55 n
56 );
57
58 drop(map);
59
60 let mut n = 0usize;
61 let mut combinations = Vec::new();
62 let map = SubsetMap::fill(&elements, |x| {
63 combinations.push(x.to_vec());
64 n += 1;
65 n
66 });
67
68 let start = Instant::now();
69
70 let mut n = 0usize;
71 for combination in combinations {
72 if let LookupResult::Perfect(Some(_p)) = map.lookup(&combination) {
73 n += 1;
74 }
75 }
76
77 println!(
78 "[LOOKUP]: Combinations: {} -> Time: {:?} {}",
79 map.size(),
80 start.elapsed(),
81 n
82 );
83
84 drop(map);
85
86 let mut n = 0usize;
87 let mut combinations = Vec::new();
88 let map = SubsetMap::fill(&elements, |x| {
89 combinations.push(x.to_vec());
90 n += 1;
91 n
92 });
93
94 let start = Instant::now();
95
96 let mut n = 0usize;
97 for combination in combinations {
98 if let FindResult::Perfect(_) = map.find(&combination) {
99 n += 1;
100 }
101 }
102
103 println!(
104 "[FIND]: Combinations: {} -> Time: {:?} {}",
105 map.size(),
106 start.elapsed(),
107 n
108 );
109}
Sourcepub fn find<'a>(&'a self, subset: &[E]) -> FindResult<'a, E, P>where
E: Eq,
pub fn find<'a>(&'a self, subset: &[E]) -> FindResult<'a, E, P>where
E: Eq,
Finds a payload by the given subset.
Elements in subset
that are not part of the initial set are
skipped.
If there was no match or no payload for the given subset
FindResult::NotFound
is returned.
Use this function if you are mostly interested in
payloads and how they were matched. Otherwise
use lookup
or get
§Example
use subset_map::*;
let subset_map = SubsetMap::new(&[1u32, 2, 3], |x| {
if x == &[2] {
None
} else {
let payload = x.iter().cloned().collect::<Vec<_>>();
Some(payload)
}
});
let empty: &[u32] = &[];
// A perfect match with a payload:
let match_result = subset_map.find(&[1]);
assert_eq!(match_result.payload(), Some(&vec![1]));
assert_eq!(match_result.is_found(), true);
assert_eq!(match_result.is_found_and_perfect(), true);
assert_eq!(match_result.is_found_and_excluded(), false);
assert_eq!(match_result.excluded_elements(), empty);
// A perfect match that has no payload:
let match_result = subset_map.find(&[2]);
assert_eq!(match_result.payload(), None);
assert_eq!(match_result.is_found(), false);
assert_eq!(match_result.is_found_and_perfect(), false);
assert_eq!(match_result.is_found_and_excluded(), false);
assert_eq!(match_result.excluded_elements(), empty);
// There is no answer at all:
let match_result = subset_map.find(&[42]);
assert_eq!(match_result.payload(), None);
assert_eq!(match_result.is_not_found(), true);
assert_eq!(match_result.is_found_and_perfect(), false);
assert_eq!(match_result.is_found_and_excluded(), false);
assert_eq!(match_result.excluded_elements(), empty);
// A nearby match but that has a payload:
let match_result = subset_map.find(&[3,1]);
assert_eq!(match_result.is_found_and_perfect(), false);
assert_eq!(match_result.is_found_and_excluded(), true);
assert_eq!(match_result.is_found(), true);
assert_eq!(match_result.payload(), Some(&vec![3]));
assert_eq!(match_result.excluded_elements(), &[1]);
Examples found in repository?
6fn main() {
7 let elements: Vec<_> = (0..17).collect();
8 let start = Instant::now();
9
10 let mut n = 0;
11 let map = SubsetMap::fill(&elements, |_x| {
12 n += 1;
13 n
14 });
15
16 println!(
17 "[CREATE_SIMPLE]: Combinations: {}(Size: {}) -> Time: {:?}",
18 n,
19 map.size(),
20 start.elapsed()
21 );
22
23 drop(map);
24
25 let start = Instant::now();
26
27 let mut n = 0usize;
28 let mut combinations = Vec::new();
29 let map = SubsetMap::fill(&elements, |x| {
30 combinations.push(x.to_vec());
31 n += 1;
32 n
33 });
34
35 println!(
36 "[CREATE_FOR_QUERY]: Combinations: {}(Size: {}) -> Time: {:?}",
37 n,
38 map.size(),
39 start.elapsed()
40 );
41
42 let start = Instant::now();
43
44 let mut n = 0usize;
45 for combination in combinations {
46 if let Some(_p) = map.get(&combination) {
47 n += 1;
48 }
49 }
50
51 println!(
52 "[GET]: Combinations: {} -> Time: {:?} {}",
53 map.size(),
54 start.elapsed(),
55 n
56 );
57
58 drop(map);
59
60 let mut n = 0usize;
61 let mut combinations = Vec::new();
62 let map = SubsetMap::fill(&elements, |x| {
63 combinations.push(x.to_vec());
64 n += 1;
65 n
66 });
67
68 let start = Instant::now();
69
70 let mut n = 0usize;
71 for combination in combinations {
72 if let LookupResult::Perfect(Some(_p)) = map.lookup(&combination) {
73 n += 1;
74 }
75 }
76
77 println!(
78 "[LOOKUP]: Combinations: {} -> Time: {:?} {}",
79 map.size(),
80 start.elapsed(),
81 n
82 );
83
84 drop(map);
85
86 let mut n = 0usize;
87 let mut combinations = Vec::new();
88 let map = SubsetMap::fill(&elements, |x| {
89 combinations.push(x.to_vec());
90 n += 1;
91 n
92 });
93
94 let start = Instant::now();
95
96 let mut n = 0usize;
97 for combination in combinations {
98 if let FindResult::Perfect(_) = map.find(&combination) {
99 n += 1;
100 }
101 }
102
103 println!(
104 "[FIND]: Combinations: {} -> Time: {:?} {}",
105 map.size(),
106 start.elapsed(),
107 n
108 );
109}
Sourcepub fn filter_values<F>(&mut self, predicate: F)
pub fn filter_values<F>(&mut self, predicate: F)
Sets the payload of all subsets to None
where the given payload does not fulfill the predicate
Sourcepub fn walk_values<F>(&self, f: F)
pub fn walk_values<F>(&self, f: F)
Executes the given mutable closure f
on the value of each node.
Sourcepub fn walk_values_until<F>(&self, f: F)
pub fn walk_values_until<F>(&self, f: F)
Executes the given mutable closure f
on the value of each node until the
first closure returns false.
Sourcepub fn walk_payloads<F>(&self, f: F)
pub fn walk_payloads<F>(&self, f: F)
Executes the given mutable closure f
on the payload of each node
Sourcepub fn walk_payloads_until<F>(&self, f: F)
pub fn walk_payloads_until<F>(&self, f: F)
Executes the given mutable closure f
on the payload of each node until the
first closure returns false.
Sourcepub fn for_each_value<F>(&self, f: F)
pub fn for_each_value<F>(&self, f: F)
Executes the given mutable closure f
on the payload of each node
Sourcepub fn for_each_payload<F>(&self, f: F)
pub fn for_each_payload<F>(&self, f: F)
Executes the given mutable closure f
on the payload of each node
Sourcepub fn all_subsets_have_values(&self) -> bool
pub fn all_subsets_have_values(&self) -> bool
Returns true if there are nodes and all of these have a payload set.
Sourcepub fn no_subset_with_value(&self) -> bool
pub fn no_subset_with_value(&self) -> bool
Returns true if there are no subsets or all of these have no payload set.
§Example
An empty map has no values:
use subset_map::*;
let subset_map = SubsetMap::<u8, u8>::with_default(&[]);
assert_eq!(subset_map.no_subset_with_value(), true);
An map with a set entry has values:
use subset_map::*;
let subset_map = SubsetMap::<u8, u8>::with_default(&[1]);
assert_eq!(subset_map.no_subset_with_value(), false);
An non empty map where at least one subset has a value:
use subset_map::*;
let mut subset_map = SubsetMap::fill(&[1, 2], |c| c.len());
subset_map.filter_values(|p| *p == 2);
assert_eq!(subset_map.no_subset_with_value(), false);
An non empty map where no subset has a value:
use subset_map::*;
let mut subset_map = SubsetMap::<u8, u8>::with_default(&[1, 2]);
// Set all payloads to `None`
subset_map.filter_values(|p| false);
assert_eq!(subset_map.no_subset_with_value(), true);
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
The number of subsets in this map
Examples found in repository?
6fn main() {
7 let elements: Vec<_> = (0..17).collect();
8 let start = Instant::now();
9
10 let mut n = 0;
11 let map = SubsetMap::fill(&elements, |_x| {
12 n += 1;
13 n
14 });
15
16 println!(
17 "[CREATE_SIMPLE]: Combinations: {}(Size: {}) -> Time: {:?}",
18 n,
19 map.size(),
20 start.elapsed()
21 );
22
23 drop(map);
24
25 let start = Instant::now();
26
27 let mut n = 0usize;
28 let mut combinations = Vec::new();
29 let map = SubsetMap::fill(&elements, |x| {
30 combinations.push(x.to_vec());
31 n += 1;
32 n
33 });
34
35 println!(
36 "[CREATE_FOR_QUERY]: Combinations: {}(Size: {}) -> Time: {:?}",
37 n,
38 map.size(),
39 start.elapsed()
40 );
41
42 let start = Instant::now();
43
44 let mut n = 0usize;
45 for combination in combinations {
46 if let Some(_p) = map.get(&combination) {
47 n += 1;
48 }
49 }
50
51 println!(
52 "[GET]: Combinations: {} -> Time: {:?} {}",
53 map.size(),
54 start.elapsed(),
55 n
56 );
57
58 drop(map);
59
60 let mut n = 0usize;
61 let mut combinations = Vec::new();
62 let map = SubsetMap::fill(&elements, |x| {
63 combinations.push(x.to_vec());
64 n += 1;
65 n
66 });
67
68 let start = Instant::now();
69
70 let mut n = 0usize;
71 for combination in combinations {
72 if let LookupResult::Perfect(Some(_p)) = map.lookup(&combination) {
73 n += 1;
74 }
75 }
76
77 println!(
78 "[LOOKUP]: Combinations: {} -> Time: {:?} {}",
79 map.size(),
80 start.elapsed(),
81 n
82 );
83
84 drop(map);
85
86 let mut n = 0usize;
87 let mut combinations = Vec::new();
88 let map = SubsetMap::fill(&elements, |x| {
89 combinations.push(x.to_vec());
90 n += 1;
91 n
92 });
93
94 let start = Instant::now();
95
96 let mut n = 0usize;
97 for combination in combinations {
98 if let FindResult::Perfect(_) = map.find(&combination) {
99 n += 1;
100 }
101 }
102
103 println!(
104 "[FIND]: Combinations: {} -> Time: {:?} {}",
105 map.size(),
106 start.elapsed(),
107 n
108 );
109}