Try to add value to the bucket. If bucket is empty or key is the same, does insert and return True. If bucket has another key that means that we need to check next bucket.
(self, ind: int, key: KEY, val: VAL)
| 67 | return (ind + 1) % len(self._buckets) |
| 68 | |
| 69 | def _try_set(self, ind: int, key: KEY, val: VAL) -> bool: |
| 70 | """ |
| 71 | Try to add value to the bucket. |
| 72 | |
| 73 | If bucket is empty or key is the same, does insert and return True. |
| 74 | |
| 75 | If bucket has another key that means that we need to check next bucket. |
| 76 | """ |
| 77 | stored = self._buckets[ind] |
| 78 | if not stored: |
| 79 | # A falsy item means that bucket was never used (None) |
| 80 | # or was deleted (_deleted). |
| 81 | self._buckets[ind] = _Item(key, val) |
| 82 | self._len += 1 |
| 83 | return True |
| 84 | elif stored.key == key: |
| 85 | stored.val = val |
| 86 | return True |
| 87 | else: |
| 88 | return False |
| 89 | |
| 90 | def _is_full(self) -> bool: |
| 91 | """ |