MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / _is_full

Method _is_full

data_structures/hashing/hash_map.py:90–105  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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."""

Callers 1

__setitem__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected