(self, sequence_id: int, keep_len: int)
| 936 | return self.sequence_lengths.get(sequence_id, 0) |
| 937 | |
| 938 | def truncate(self, sequence_id: int, keep_len: int) -> None: |
| 939 | assert sequence_id >= 0 |
| 940 | assert sequence_id in self.sequence_lengths |
| 941 | assert 0 <= keep_len <= self.sequence_lengths[sequence_id] |
| 942 | current_len = self.sequence_lengths[sequence_id] |
| 943 | if keep_len == current_len: |
| 944 | return |
| 945 | boundary = self._locate_prefix_node(sequence_id, keep_len) |
| 946 | node = self.sequences.get(sequence_id, self.root) |
| 947 | if node is not self.root: |
| 948 | node.tails.discard(sequence_id) |
| 949 | while node is not boundary: |
| 950 | node.sequences.remove(sequence_id) |
| 951 | parent = node.parent |
| 952 | assert parent is not None |
| 953 | if not node.sequences: |
| 954 | del parent.children[node.label[0]] |
| 955 | node = parent |
| 956 | if boundary is self.root: |
| 957 | self.sequences.pop(sequence_id, None) |
| 958 | self.sequence_lengths.pop(sequence_id, None) |
| 959 | else: |
| 960 | self.sequences[sequence_id] = boundary |
| 961 | self.sequence_lengths[sequence_id] = keep_len |
| 962 | boundary.tails.add(sequence_id) |
| 963 | |
| 964 | def copy(self, source_sequence_id: int, dest_sequence_id: int, keep_len: int) -> None: |
| 965 | assert source_sequence_id >= 0 |
no test coverage detected