RFR: 8300487: Store cardinality as a field in BitSet [v5]
Martin Buchholz
martin at openjdk.org
Thu Jan 19 22:39:33 UTC 2023
On Wed, 18 Jan 2023 12:43:31 GMT, fabioromano1 <duke at openjdk.org> wrote:
>> The enanchment is useful for applications that make heavy use of BitSet objects as sets of integers, and therefore they need to make a lot of calls to cardinality() method, which actually require linear time in the number of words in use by the bit set.
>> This optimization reduces the cost of calling cardinality() to constant time, as it simply returns the value of the field, and it also try to make as little effort as possible to update the field, when needed.
>>
>> Moreover, it has been implemented a new method for testing wheter a bit set includes another bit set (i.e., the set of true bits of the parameter is a subset of the true bits of the instance).
>
> fabioromano1 has updated the pull request incrementally with one additional commit since the last revision:
>
> Added author and reverse the cicle order in includes(BitSet)
On Thu, Jan 19, 2023 at 1:15 PM fabioromano1 ***@***.***>
wrote:
> The patch has passed all existing tests of the class
>
Existing tests are very unlikely to be good enough when introducing a new
invariant that all mutating methods need to maintain.
As an example of what to look out for, you want to eliminate the
possibility of an exception being thrown between the update of the long[]
and the update of the cardinality field, and testing for that sort of thing
is rarely done well.
> Message ID: ***@***.***>
>
-------------
PR: https://git.openjdk.org/jdk/pull/11837
More information about the core-libs-dev
mailing list