Skip to content

Commit

Permalink
Actually use bitMatrix, remove gonum, and some minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
liamsi committed Apr 5, 2021
1 parent 8e170ab commit 2d7373d
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 222 deletions.
6 changes: 2 additions & 4 deletions bit_matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ type bitMatrix struct {
squareSize int
}

func newBitMatrix(squareSize, bits int) bitMatrix {
if squareSize*squareSize != bits {
panic(fmt.Sprintf("invalid arguments %v*%v != %v", squareSize, squareSize, bits))
}
func newBitMatrix(squareSize int) bitMatrix {
bits := squareSize * squareSize
return bitMatrix{mask: make([]uint64, (bits+63)/64), squareSize: squareSize}
}

Expand Down
14 changes: 7 additions & 7 deletions bit_matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Test_bitMatrix_ColRangeIsOne(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bm := newBitMatrix(tt.initParams.squareSize, tt.initParams.bits)
bm := newBitMatrix(tt.initParams.squareSize)
for _, flatIdx := range tt.setBits {
bm.SetFlat(flatIdx)
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func Test_bitMatrix_ColumnIsOne(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bm := newBitMatrix(tt.initParams.squareSize, tt.initParams.bits)
bm := newBitMatrix(tt.initParams.squareSize)
for _, flatIdx := range tt.setBits {
bm.SetFlat(flatIdx)
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func Test_bitMatrix_Get(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bm := newBitMatrix(tt.initParams.squareSize, tt.initParams.bits)
bm := newBitMatrix(tt.initParams.squareSize)
for _, ind := range tt.setIndices {
bm.Set(ind.row, ind.col)
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func Test_bitMatrix_NumOnesInCol(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bm := newBitMatrix(tt.initParams.squareSize, tt.initParams.bits)
bm := newBitMatrix(tt.initParams.squareSize)
for _, flatIdx := range tt.setBits {
bm.SetFlat(flatIdx)
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func Test_bitMatrix_NumOnesInRow(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bm := newBitMatrix(tt.initParams.squareSize, tt.initParams.bits)
bm := newBitMatrix(tt.initParams.squareSize)
for _, flatIdx := range tt.setBits {
bm.SetFlat(flatIdx)
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func Test_bitMatrix_RowIsOne(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bm := newBitMatrix(tt.initParams.squareSize, tt.initParams.bits)
bm := newBitMatrix(tt.initParams.squareSize)
for _, flatIdx := range tt.setBits {
bm.SetFlat(flatIdx)
}
Expand Down Expand Up @@ -315,7 +315,7 @@ func Test_bitMatrix_RowRangeIsOne(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bm := newBitMatrix(tt.initParams.squareSize, tt.initParams.bits)
bm := newBitMatrix(tt.initParams.squareSize)
for _, flatIdx := range tt.setBits {
bm.SetFlat(flatIdx)
}
Expand Down
Loading

0 comments on commit 2d7373d

Please sign in to comment.