Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison to empty set returns false for set with no bits set. #71

Closed
John-Nagle opened this issue Dec 18, 2021 · 6 comments
Closed

Comparison to empty set returns false for set with no bits set. #71

John-Nagle opened this issue Dec 18, 2021 · 6 comments

Comments

@John-Nagle
Copy link

"Eq" is true only if the number of bits in the underlying representation is the same. Comparing a bitset against
FixedBitSet::new() is not necessarily true for the empty set.

@John-Nagle
Copy link
Author

Maybe define "is_empty()"

@jrraymond
Copy link
Collaborator

I see how this could be unintuitive. is_empty already exists.
This is the second time someone has raised this issue ( #44 ) so I'll update the docs to make this behavior clear.

@John-Nagle
Copy link
Author

Thanks.
I'll use .is_empty().
As for equality, I think it should be either logical set equality, or not defined at all. Equality of the underlying representation is not what one expects.

@jrraymond
Copy link
Collaborator

clarification: is_empty already exists but doesn't do what you want. To compare the number of 1s are equal you can use xs.ones().eq(ys.ones())

The number of 0s isn't part of the underlying implementation. Its already exposed via other methods. There is more discussion on this in #44.

@John-Nagle
Copy link
Author

clarification: is_empty already exists but doesn't do what you want.

No, it sure doesn't.

pub fn is_empty(&self) -> bool {
        self.len() == 0
}

That's "is any storage allocated", not "are there any entries".

The documentation does not say that. It needs to be made much, much clearer that "bitset" doesn't work like set theory, so that people are warned away from using it.

@jrraymond
Copy link
Collaborator

FixedBitSet is a simple fixed size set of bits that each can be enabled (1 / true) or disabled (0 / false) is clear imo. Bitsets in general are not synonymous with sets of non-negative integers.

Suggestions welcome, snark not appreciated 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants