def impl_delitem(self, w_key): space = self.space w_key_type = space.type(w_key) if space.is_w(w_key_type, space.w_str): key = space.str_w(w_key) pos = self.structure.lookup_position(key) if pos == -1: raise KeyError struct_len = self.structure.length num_back = struct_len - pos - 1 if num_back > 0: for i in range(pos, struct_len - 1): self.entries[i] = self.entries[i + 1] # don't make the entries list shorter, new keys might be added soon self.entries[struct_len - 1] = None structure = self.structure keys = [None] * num_back for i in range(num_back): keys[i] = structure.last_key structure = structure.back_struct # go back the structure that contains the deleted key structure = structure.back_struct for i in range(num_back - 1, -1, -1): structure = structure.get_next_structure(keys[i]) self.structure = structure elif _is_sane_hash(space, w_key_type): raise KeyError else: self._as_rdict().delitem(w_key)
def impl_getitem(self, w_lookup): space = self.space w_lookup_type = space.type(w_lookup) if space.is_w(w_lookup_type, space.w_str): return self.impl_getitem_str(space.str_w(w_lookup)) elif _is_sane_hash(space, w_lookup_type): return None else: return self._as_rdict().getitem(w_lookup)
def get(self, w_lookup): space = self.space w_lookup_type = space.type(w_lookup) if space.is_w(w_lookup_type, space.w_str): res = self.getcell(space.str_w(w_lookup), False) if res is None: return None return res.w_value elif _is_sane_hash(space, w_lookup_type): return None else: return self._as_rdict().get(w_lookup)
def get(self, w_lookup): space = self.space w_lookup_type = space.type(w_lookup) if space.is_w(w_lookup_type, space.w_str): try: return self.getcell(space.str_w(w_lookup), False).w_value except KeyError: return None elif _is_sane_hash(space, w_lookup_type): return None else: return self._as_rdict().get(w_lookup)
def get(self, w_lookup): space = self.space w_lookup_type = space.type(w_lookup) if space.is_w(w_lookup_type, space.w_str): lookup = space.str_w(w_lookup) i = self.structure.lookup_position(lookup) if i == -1: return None return self.entries[i] elif _is_sane_hash(space, w_lookup_type): return None else: return self._as_rdict().get(w_lookup)
def delitem(self, w_key): space = self.space w_key_type = space.type(w_key) if space.is_w(w_key_type, space.w_str): key = space.str_w(w_key) cell = self.getcell(key, False) cell.invalidate() del self.content[key] return self elif _is_sane_hash(space, w_key_type): raise KeyError else: return self._as_rdict().delitem(w_key)
def delitem(self, w_key): space = self.space w_key_type = space.type(w_key) if space.is_w(w_key_type, space.w_str): key = space.str_w(w_key) if (self.structure.last_key is not None and key == self.structure.last_key): self.entries[self.structure.length - 1] = None self.structure = self.structure.back_struct return self return self._as_rdict().delitem(w_key) elif _is_sane_hash(space, w_key_type): raise KeyError else: return self._as_rdict().delitem(w_key)
def delitem(self, w_key): space = self.space w_key_type = space.type(w_key) if space.is_w(w_key_type, space.w_str): key = space.str_w(w_key) cell = self.getcell(key, False) if cell is None: raise KeyError cell.invalidate() del self.content[key] return self elif _is_sane_hash(space, w_key_type): raise KeyError else: return self._as_rdict().delitem(w_key)
def impl_delitem(self, w_key): space = self.space w_key_type = space.type(w_key) if space.is_w(w_key_type, space.w_str): key = space.str_w(w_key) cell = self.getcell(key, False) if cell is None or cell.w_value is None: raise KeyError # note that we don't remove the cell from self.content, to make # sure that a key that was found at any point in the dict, still # maps to the same cell later (even if this cell no longer # represents a key) cell.invalidate() elif _is_sane_hash(space, w_key_type): raise KeyError else: self._as_rdict().delitem(w_key)