MCPcopy
hub / github.com/keon/algorithms / remove

Method remove

algorithms/map/randomized_set.py:53–68  ·  view source on GitHub ↗

Remove a value from the set. Args: val: Value to remove. Returns: True if the value was removed, False if not present.

(self, val: int)

Source from the content-addressed store, hash-verified

51 return False
52
53 def remove(self, val: int) -> bool:
54 """Remove a value from the set.
55
56 Args:
57 val: Value to remove.
58
59 Returns:
60 True if the value was removed, False if not present.
61 """
62 if val in self.idxs:
63 idx, last = self.idxs[val], self.nums[-1]
64 self.nums[idx], self.idxs[last] = last, idx
65 self.nums.pop()
66 self.idxs.pop(val, 0)
67 return True
68 return False
69
70 def get_random(self) -> int:
71 """Return a random element from the set.

Callers 6

tearDownMethod · 0.45
_remove_keyMethod · 0.45
ladder_lengthFunction · 0.45
_expand_cliqueFunction · 0.45
_valid_oneMethod · 0.45

Calls 1

popMethod · 0.45

Tested by 1

tearDownMethod · 0.36