| Crates.io | subset-map |
| lib.rs | subset-map |
| version | 0.3.4 |
| created_at | 2018-04-30 08:25:10.867276+00 |
| updated_at | 2020-01-29 14:45:45.925776+00 |
| description | A map where the keys are subsets of an initial set of elements |
| homepage | https://github.com/chridou/subset-map |
| repository | https://github.com/chridou/subset-map |
| max_upload_size | |
| id | 63108 |
| size | 56,864 |
subset-map is a map like data structure where the keys are combinations
of elements the SubsetMap has been initialized with.
The order of the elements is defined by the position of an element
within the elements the SubsetMap has been initialized with.
SubsetMap clones the elements into the subsets. So you should
consider to only use element types where you would feel good to assign
them the Copy trait.
Lookup is done linearly. Therefore SubsetMap should only be used
with not too big sets of elements.
use subset_map::*;
// Initialize the map where the payloads are basically the keys
let subset_map = SubsetMap::fill(&[1, 2, 3], |x| x.iter().cloned().collect::<Vec<_>>());
assert_eq!(subset_map.get(&[1]), Some(&vec![1]));
assert_eq!(subset_map.get(&[2]), Some(&vec![2]));
assert_eq!(subset_map.get(&[3]), Some(&vec![3]));
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]));
// No internal ordering is performed:
// The position in the original set is crucial:
assert_eq!(subset_map.get(&[2,1]), None);
The serde feature allows serialization and deserialization with serde.
Recent Changes
walk method which operates on keys and valuessize functionfind and lookup a bitsize finction to return the number of combinationsLookupResultLookupResult also contains the no match casesubset-map is distributed under the terms of both the MIT license and the Apache License (Version
2.0).
Copyright(2018) Christian Douven
See LICENSE-APACHE and LICENSE-MIT for details.
License: Apache-2.0/MIT