word_tree.py 512 B

123456789101112131415161718
  1. import struct
  2. class WordBit:
  3. SIZE = 13
  4. def __init__(self):
  5. self.next_0 = None
  6. self.next_1 = None
  7. self.collection = None
  8. self.position = 0
  9. def serialise(self):
  10. n0 = self.next_0.position if self.next_0 != None else 0
  11. n1 = self.next_1.position if self.next_1 != None else 0
  12. col = self.collection if self.collection != None else 0
  13. has_col = 255 if self.collection != None else 0
  14. return struct.pack("<IBII", n0, has_col, col, n1)