Changeset View
Changeset View
Standalone View
Standalone View
swh/model/collections.py
Show All 36 Lines | def __iter__(self): | ||||
yield k | yield k | ||||
def __len__(self): | def __len__(self): | ||||
return len(self.data) | return len(self.data) | ||||
def items(self): | def items(self): | ||||
yield from self.data | yield from self.data | ||||
def __hash__(self): | |||||
return hash(tuple(sorted(self.data))) | |||||
def copy_pop(self, popped_key) -> Tuple[Optional[VT], "ImmutableDict[KT, VT]"]: | def copy_pop(self, popped_key) -> Tuple[Optional[VT], "ImmutableDict[KT, VT]"]: | ||||
"""Returns a copy of this ImmutableDict without the given key, | """Returns a copy of this ImmutableDict without the given key, | ||||
as well as the value associated to the key.""" | as well as the value associated to the key.""" | ||||
popped_value = None | popped_value = None | ||||
new_items = [] | new_items = [] | ||||
for (key, value) in self.data: | for (key, value) in self.data: | ||||
if key == popped_key: | if key == popped_key: | ||||
popped_value = value | popped_value = value | ||||
else: | else: | ||||
new_items.append((key, value)) | new_items.append((key, value)) | ||||
return (popped_value, ImmutableDict(new_items)) | return (popped_value, ImmutableDict(new_items)) |