Bitsets | Contents |

Bitsets are sets of non-negative integer elements that are implemented
in one or more words of packed bits. The internal representation of a
BitSet uses an array of `Long`s.
The first `Long` covers elements
from 0 to 63, the second from 64 to 127, and so on. ^{1}
For every `Long`,
each of its 64 bits is set to 1 if the corresponding element is
contained in the set, and is unset otherwise. It follows that the size
of a bitset depends on the largest integer that's stored in
it. If `N` is that largest integer, then the size of the set is
`N/64` `Long` words, or `N/8` bytes, plus a small number of extra bytes
for status information.

Bitsets are hence more compact than other sets if they contain many
small elements. Another advantage of bitsets is that operations such
as membership test with `contains`, or element addition and removal
with `+=` and `-=` are all extremely efficient.

Next: Maps

Bitsets | Contents |