RFR: 8300487: Store cardinality as a field in BitSet [v5]
fabioromano1
duke at openjdk.org
Thu Jan 19 12:31:43 UTC 2023
On Wed, 18 Jan 2023 21:51:02 GMT, Martin Buchholz <martin at openjdk.org> wrote:
> Like other reviewers, changing the performance tradeoffs in BitSet make me uncomfortable.
>
> 30 years of code has adapted to the current performance tradeoffs. Those users who really need O(1) cardinality() can fairly easily implement it in client code (and probably have).
>
> The spirit of BitSet is space efficiency, and adding another field negates that.
>
> cardinality() is O(N) but in practice should be very efficient due to linear traversal and (presumably) the use of hardware bitcount instructions for each word (fix that if not true).
>
> There may be a case for a BitSet rewrite (e.g. to support large sparse bitsets) once we have compact value types.
Leaving to the client the responsibility of implementation isn't against the principle of information hiding and encapsulation?
-------------
PR: https://git.openjdk.org/jdk/pull/11837
More information about the core-libs-dev
mailing list