2022-11-30 14:28:27 +00:00
|
|
|
#!/bin/python3
|
|
|
|
|
|
|
|
import random
|
2022-12-07 14:25:48 +00:00
|
|
|
from bitarray import bitarray
|
|
|
|
from bitarray.util import zeros
|
2022-11-30 14:28:27 +00:00
|
|
|
|
|
|
|
class Block:
|
|
|
|
|
|
|
|
blockSize = 0
|
2022-12-07 14:25:48 +00:00
|
|
|
data = bitarray()
|
2022-11-30 14:28:27 +00:00
|
|
|
|
|
|
|
def __init__(self, size):
|
|
|
|
self.blockSize = size
|
2022-12-07 14:25:48 +00:00
|
|
|
self.data = zeros(self.blockSize*self.blockSize)
|
2022-11-30 14:28:27 +00:00
|
|
|
|
|
|
|
def fill(self):
|
2022-12-07 17:44:02 +00:00
|
|
|
self.data.setall(1)
|
2022-11-30 14:28:27 +00:00
|
|
|
|
2022-12-07 14:10:35 +00:00
|
|
|
def getColumn(self, columnID):
|
2022-12-07 14:25:48 +00:00
|
|
|
return self.data[columnID::self.blockSize]
|
2022-12-07 14:10:35 +00:00
|
|
|
|
|
|
|
def getRow(self, rowID):
|
2022-12-07 14:25:48 +00:00
|
|
|
return self.data[rowID*self.blockSize:(rowID+1)*self.blockSize]
|
2022-12-07 14:10:35 +00:00
|
|
|
|
2022-11-30 14:28:27 +00:00
|
|
|
def print(self):
|
|
|
|
dash = "-" * (self.blockSize+2)
|
|
|
|
print(dash)
|
|
|
|
for i in range(self.blockSize):
|
|
|
|
line = "|"
|
|
|
|
for j in range(self.blockSize):
|
|
|
|
line += "%i" % self.data[(i*self.blockSize)+j]
|
|
|
|
print(line+"|")
|
|
|
|
print(dash)
|
|
|
|
|