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

Method _get_next_ind

data_structures/hashing/hash_map.py:53–67  ·  view source on GitHub ↗

Get next index. Implements linear open addressing. >>> HashMap(5)._get_next_ind(3) 4 >>> HashMap(5)._get_next_ind(5) 1 >>> HashMap(5)._get_next_ind(6) 2 >>> HashMap(5)._get_next_ind(9) 0

(self, ind: int)

Source from the content-addressed store, hash-verified

51 return hash(key) % len(self._buckets)
52
53 def _get_next_ind(self, ind: int) -> int:
54 """
55 Get next index.
56
57 Implements linear open addressing.
58 >>> HashMap(5)._get_next_ind(3)
59 4
60 >>> HashMap(5)._get_next_ind(5)
61 1
62 >>> HashMap(5)._get_next_ind(6)
63 2
64 >>> HashMap(5)._get_next_ind(9)
65 0
66 """
67 return (ind + 1) % len(self._buckets)
68
69 def _try_set(self, ind: int, key: KEY, val: VAL) -> bool:
70 """

Callers 1

_iterate_bucketsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected