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

BooleanMap/Set implementations should delegate to a super simple data structure #131

Open
techsy730 opened this issue Jul 17, 2019 · 10 comments

Comments

@techsy730
Copy link
Contributor

Instead of having grand data structures for a keyspace of only 2 elements, all BooleanMap/Set implementations should delegate to a super simple implementation that only has whether true is present, whether false is present, and for maps, the true value and the false value. This should be super fast and super compact in memory.

The only complexity would be that for some implementations, a sorted order needs to be maintained (those that implement SortedBooleanMap/Set). In others, we need to maintain insertion order. (For implementations that do not assure a key order, we can just use the sorted order for free).

@techsy730 techsy730 changed the title BooleanMap/Set implementations should delegate to a super simple implementation BooleanMap/Set implementations should delegate to a super simple data structure Jul 17, 2019
@techsy730
Copy link
Contributor Author

techsy730 commented Jul 18, 2019

Oh, I didn't notice that there aren't even Boolean2WhateverMaps generated. So I guess make this feature request only about BooleanSet

@vigna
Copy link
Owner

vigna commented Jul 18, 2019

"All BooleanMap/Set implementations" sounds a bit grand for a single implementation: BooleanOpenHashSet. LOL.

@techsy730
Copy link
Contributor Author

Yep, the whole point is that something like "BooleanOpenHashSet" is complete overkill for booleans. It should just be two boolean variables (whether true and false are present). All of the boolean sets should be. The only reason I didn't suggest getting rid of all the boolean set implementations and just have one or two of this sort of super simple implementation is for backwards compatibility.

@vigna
Copy link
Owner

vigna commented Jul 19, 2019

Ok. In the interest of clarity, can you name another implementation beside BooleanOpenHashSet?

@techsy730
Copy link
Contributor Author

techsy730 commented Aug 21, 2019

Hmm, looking over it, BooleanOpenHashSet and BooleanArraySet are the only concrete set type for booleans currently. There isn't even a SortedSet implementation.

So I guess then we can just make a new set implementation, BooleanSimpleSet or BooleanFastSet or BooleanDirectSet or something, that is just two boolean member variables.

Optionally, we can then make those two set implementations delegate to that implementation (though care would be needed for BooleanArraySet to preserve insertion order)

@leventov
Copy link

+1. BooleanOpenHashSet and BooleanArraySet should be deprecated.

@vigna
Copy link
Owner

vigna commented Oct 29, 2019

I'd just write ten-line specific implementations of those, with a two-element boolean array remembering whether true or false are in the set. Pull requests, anybody?

@vigna vigna closed this as completed Dec 21, 2020
@techsy730
Copy link
Contributor Author

I might be willing to try this. I just had my hands full with the Spliterator stuff at the time.
However, implementing NavigableMap may be a better first step.

@vigna
Copy link
Owner

vigna commented Dec 22, 2020

Yes I would try to release 8.5.0 with #162 and the attack navigabile. There's even a proposal from 2017 with the interfaces 🙈.

@vigna vigna reopened this Dec 22, 2020
@techsy730
Copy link
Contributor Author

Given that a boolean set can have only 4 possible states, {}, {false}, {true}, and {false, true}, it would make sense to have an immutable boolean set implementation alongside the mutable one.

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

3 participants