Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
simple BitMap impl.
case class BitMap(val n: Int) {
private val bytes = Array.fill(n / 8 + 1)(0.toByte)
def setBit(i: Int) {
bytes(i / 8) = (bytes(i / 8) | (1 << (i & 7))).toByte
}
def unSetBit(i: Int) {
bytes(i / 8) = (bytes(i / 8) & ~(1 << (i & 7))).toByte
}
def getBit(i: Int): Boolean = {
(bytes(i / 8) & (1 << (i & 7))) > 0
}
}
@advancedxy

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment