def save(self, s: AbstractIO): s.add_uint(len(self)) curblock = self._search_map.__iter__() left = len(self) index = 0 level = 0 stack = list() while level > -1: if left > 0: node = next(curblock) el = node.content if el.kind == ElementKind.PARAM: s.add_byte(int(ElementKind.PARAM)) s.add_widestr(el.name) s.add_widestr(el.content) left -= 1 elif el.kind == ElementKind.BLOCK: s.add_byte(int(ElementKind.BLOCK)) s.add_widestr(el.name) stack.append((curblock, left, index)) curblock = el.content._search_map.__iter__() left = len(el.content) s.add_uint(left) level += 1 else: if level > 0: curblock, left, index = stack.pop() left -= 1 level -= 1
def save(self, s: AbstractIO, *, new_format: bool = False): s.add_bool(self.sorted) s.add_uint(len(self)) is_sort = self.sorted if is_sort: curblock = self._search_map.__iter__() else: curblock = self._order_map.__iter__() left = len(self) count = 1 index = 0 level = 0 stack = list() while level > -1: if left > 0: node = next(curblock) el = node.content if new_format and is_sort: if node.count > 1: count = node.count index = 0 s.add_uint(index) if index == 0: s.add_uint(count) else: s.add_uint(0) if el.kind == ElementKind.PARAM: s.add_byte(int(ElementKind.PARAM)) s.add_widestr(el.name) s.add_widestr(el.content) left -= 1 index += 1 if index >= count: count = 1 index = 0 elif el.kind == ElementKind.BLOCK: s.add_byte(int(ElementKind.BLOCK)) s.add_widestr(el.name) stack.append((curblock, left, is_sort, count, index)) is_sort = el.content.sorted if is_sort: curblock = el.content._search_map.__iter__() else: curblock = el.content._order_map.__iter__() left = len(el.content) count = 1 index = 0 s.add_bool(is_sort) s.add_uint(left) level += 1 else: if level > 0: curblock, left, is_sort, count, index = stack.pop() left -= 1 index += 1 if index >= count: count = 1 index = 0 level -= 1