Skip to content

SortedVectorSet::is_subset is reversed #67

Description

@zkonge

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:

pub fn is_subset(&self, other: &SortedVectorSet<T>) -> 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

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

pub fn is_subset(&self, other: &SortedVectorSet<T>) -> bool {
    self.difference(other).next().is_none()
}

This matches the doc comment and standard set semantics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions