12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- var BufferUtil = require('../utils/buffer')
- function BitMatrix (size) {
- if (!size || size < 1) {
- throw new Error('BitMatrix size must be defined and greater than 0')
- }
- this.size = size
- this.data = BufferUtil.alloc(size * size)
- this.reservedBit = BufferUtil.alloc(size * size)
- }
- BitMatrix.prototype.set = function (row, col, value, reserved) {
- var index = row * this.size + col
- this.data[index] = value
- if (reserved) this.reservedBit[index] = true
- }
- BitMatrix.prototype.get = function (row, col) {
- return this.data[row * this.size + col]
- }
- BitMatrix.prototype.xor = function (row, col, value) {
- this.data[row * this.size + col] ^= value
- }
- BitMatrix.prototype.isReserved = function (row, col) {
- return this.reservedBit[row * this.size + col]
- }
- module.exports = BitMatrix
|