Skip to content

Instantly share code, notes, and snippets.

@advancedxy
Created January 29, 2015 07:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save advancedxy/084874058204d7dc80d2 to your computer and use it in GitHub Desktop.
Save advancedxy/084874058204d7dc80d2 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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