facebookexperimental / facebookexperimental/rust-shed
SortedVectorSet::is_subset is reversed
- Dominant language
- Rust
- Stars
- 147
- Forks
- 48
- PR merge metrics
- No merged PRs in 30d
Description
In `sorted_vector_map` v0.2.0, `SortedVectorSet::is_subset` appears to implement the opposite relation.
**Current docs:**
`self` is a subset of `other` (i.e. `self ⊆ other`)
**Current code:**
```rust
pub fn is_subset(&self, other: &SortedVectorSet) -> bool {
other.difference(self).next().is_none()
}
```
`other.difference(self).is_empty()` checks whether `other ⊆ self`, so the implementation is reversed.
`is_superset` delegates to `other.is_subset(self)`, so it becomes reversed as well.
### Repro
```rust
use sorted_vector_map::sorted_vector_set;
#[test]
fn subset_semantics() {
let a = sorted_vector_set! { 1, 2 };
let b = sorted_vector_set! { 1, 2, 3 };
assert!(a.is_subset(&b)); // expected true
assert!(!b.is_subset(&a)); // expected false
assert!(b.is_superset(&a)); // expected true
assert!(!a.is_superset(&b)); // expected false
}
```
### Suggested fix
```rust
pub fn is_subset(&self, other: &SortedVectorSet) -> bool {
self.difference(other).next().is_none()
}
```
This matches the doc comment and standard set semantics.
Contributor guide
Assessment
This issue has not been assessed yet.