def _read_root(self): """Create a root node from the first byte of a block""" STARTS_CHAIN, MATCHES, NUM_CHILDREN = unpack_metadata(self.block[0]) if MATCHES: pointer = pack_bytes(self.block[1:1+self.pointer_size]) next_pos = 1 + self.pointer_size else: pointer = None next_pos = 1 new_node = Node((STARTS_CHAIN > 0), None, NUM_CHILDREN, pointer) if new_node.starts_chain: next_pos = self.read_chain(new_node, next_pos) return new_node, next_pos
def _read_labeled_node(self, position): """Read a branch or chain head into a new :class:`Node` object""" in_edge = self.block[position+1] STARTS_CHAIN, MATCHES, NUM_CHILDREN = unpack_metadata(self.block[position]) if MATCHES: pointer = pack_bytes(self.block[position+2:position+2+self.pointer_size]) next_pos = position + 2 + self.pointer_size elif NUM_CHILDREN == 0: raise Exception("Node doesn't match but has no children!") else: pointer = None next_pos = position + 2 new_node = Node((STARTS_CHAIN > 0), in_edge, NUM_CHILDREN, pointer) return new_node, next_pos