Return true if we have reached safe capacity. So we need to increase the number of buckets to avoid collisions. >>> hm = HashMap(2) >>> hm._add_item(1, 10) >>> hm._add_item(2, 20) >>> hm._is_full() True >>> HashMap(2)._is_full()
(self)
| 88 | return False |
| 89 | |
| 90 | def _is_full(self) -> bool: |
| 91 | """ |
| 92 | Return true if we have reached safe capacity. |
| 93 | |
| 94 | So we need to increase the number of buckets to avoid collisions. |
| 95 | |
| 96 | >>> hm = HashMap(2) |
| 97 | >>> hm._add_item(1, 10) |
| 98 | >>> hm._add_item(2, 20) |
| 99 | >>> hm._is_full() |
| 100 | True |
| 101 | >>> HashMap(2)._is_full() |
| 102 | False |
| 103 | """ |
| 104 | limit = len(self._buckets) * self._capacity_factor |
| 105 | return len(self) >= int(limit) |
| 106 | |
| 107 | def _is_sparse(self) -> bool: |
| 108 | """Return true if we need twice fewer buckets when we have now.""" |