You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1014 B
31 lines
1014 B
4 years ago
|
# refset - non-owning `HsahSet`
|
||
|
|
||
|
A hash-set analogue that does not own its data.
|
||
|
|
||
|
It can be used to "mark" items without the need to transfer ownership to the map
|
||
|
|
||
|
# Example use case
|
||
|
```rust
|
||
|
/// Process arguments while ignoring duplicates
|
||
|
fn process_args(args: impl IntoIterator<Item=String>) {
|
||
|
let mut same= HashRefSet::new();
|
||
|
for argument in args.into_iter()
|
||
|
{
|
||
|
if !same.insert(argument.as_str()) {
|
||
|
// Already processed this input, ignore
|
||
|
continue;
|
||
|
}
|
||
|
//do work...
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
# Serialisation support with `serde` crate
|
||
|
`HashRefSet` and `HashType` both implement `Serialize` and `Deserialize` from the `serde` crate if the `serde` feature is enabled. By default it is not.
|
||
|
|
||
|
# Drawbacks
|
||
|
Since the item is not inserted itself, we cannot use `Eq` to double check there was not a hash collision.
|
||
|
While the hashing algorithm used (Sha512) is extremely unlikely to produce collisions, especially for small data types, keep in mind that it is not infallible.
|
||
|
|
||
|
# License
|
||
|
MIT
|