Skip to content

Instantly share code, notes, and snippets.

@jraczak
Created April 26, 2018 00:16
Show Gist options
  • Save jraczak/3710008c9892b21f1b0e9037ffc72f48 to your computer and use it in GitHub Desktop.
Save jraczak/3710008c9892b21f1b0e9037ffc72f48 to your computer and use it in GitHub Desktop.
Bitset.java, cardinality
public int cardinality() {
if (byteArray == null || isNull()) return 0;
int bitsOn = 0;
for (int i = 0; i < maxSize; i++) {
if (contains(i)) bitsOn++;
}
return bitsOn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment