def _add_seen_string_value(self, text): # if self.seen_string_count == len(self.shared_values): if self.shared_values: if self.seen_string_count == MAX_SHARED_STRING_VALUES: self.seen_string_count = 0 self.shared_values = [None] * len(self.shared_values) else: old = copy.copy(self.shared_values) self.shared_values = [None] * MAX_SHARED_STRING_VALUES mask = MAX_SHARED_STRING_VALUES - 1 for node in old: while node: ix = util.hash_string(node.value) & mask next_node = node.next try: node.next = self.shared_values[ix] except IndexError: node.next = None self.shared_values[ix] = node node = next_node # ref = self.seen_string_count if _is_valid_back_ref(len(self.shared_values)): ix = util.hash_string(text) & (len(self.shared_values) - 1) self.shared_values[ix] = SharedStringNode( text, ref, self.shared_values[ix])
def _add_seen_name(self, name): # if self.seen_name_count == len(self.shared_keys): if self.shared_keys: if len(self.shared_keys) == MAX_SHARED_NAMES: # self.seen_name_count = 0 self.shared_keys = [None] * len(self.shared_keys) else: old = copy.copy(self.shared_keys) self.shared_keys = [None] * MAX_SHARED_NAMES mask = MAX_SHARED_NAMES - 1 for node in old: while node: ix = util.hash_string(node.value) & mask next_node = node.next try: node.next = self.shared_keys[ix] except IndexError: node.next = None self.shared_keys[ix] = node node = next_node # ref = self.seen_name_count if _is_valid_back_ref(len(self.shared_keys)): ix = util.hash_string(name) & (len(self.shared_keys) - 1) self.shared_keys[ix] = SharedStringNode( name, ref, self.shared_keys[ix])
def _find_seen_string_value(self, text): hash_ = util.hash_string(text) try: head = self.shared_values[hash_ & (len(self.shared_values) - 1)] except IndexError: return -1 if head is None: return -1 node = head while node: if node.value is text: return node.index node = node.next node = head while node: if util.hash_string(node.value) == hash_ and node.value == text: return node.index node = node.next
def _find_seen_name(self, name): n_hash = util.hash_string(name) try: head = self.shared_keys[n_hash & (len(self.shared_keys) - 1)] except IndexError: return -1 if head is None: return -1 if head.value is name: return head.index node = head while node: if node.value is name: return node.index node = node.next node = head while node: if node.value == name and util.hash_string(node.value) == n_hash: return node.index node = node.next
def _add_seen_string_value(self, text): # if self.seen_string_count == len(self.shared_values): if self.shared_values: if self.seen_string_count == MAX_SHARED_STRING_VALUES: self.seen_string_count = 0 self.shared_values = [None] * len(self.shared_values) else: old = copy.copy(self.shared_values) self.shared_values = [None] * MAX_SHARED_STRING_VALUES mask = MAX_SHARED_STRING_VALUES - 1 for node in old: while node: ix = util.hash_string(node.value) & mask next_node = node.next try: node.next = self.shared_values[ix] except IndexError: node.next = None self.shared_values[ix] = node node = next_node # ref = self.seen_string_count if _is_valid_back_ref(len(self.shared_values)): ix = util.hash_string(text) & (len(self.shared_values) - 1) self.shared_values[ix] = SharedStringNode(text, ref, self.shared_values[ix])
def _add_seen_name(self, name): # if self.seen_name_count == len(self.shared_keys): if self.shared_keys: if len(self.shared_keys) == MAX_SHARED_NAMES: # self.seen_name_count = 0 self.shared_keys = [None] * len(self.shared_keys) else: old = copy.copy(self.shared_keys) self.shared_keys = [None] * MAX_SHARED_NAMES mask = MAX_SHARED_NAMES - 1 for node in old: while node: ix = util.hash_string(node.value) & mask next_node = node.next try: node.next = self.shared_keys[ix] except IndexError: node.next = None self.shared_keys[ix] = node node = next_node # ref = self.seen_name_count if _is_valid_back_ref(len(self.shared_keys)): ix = util.hash_string(name) & (len(self.shared_keys) - 1) self.shared_keys[ix] = SharedStringNode(name, ref, self.shared_keys[ix])