Maps that Hash
numpy
for fixed-size storagehash()
functionsize
: Number of slots in the arraytable
: Numpy array of lists to store key-value pairs_hash(key: str) -> int
hash()
and modulo operation to ensure the key maps within array boundsput(key: str, value: int) -> None
get(key: str) -> int | None
None
if key not foundremove(key: str) -> None
HashMap
instanceh = HashMap()
print(h, h.size, h.table)
h.put(261, "Software Development")
h.put(262, "Web Development")
h.put(276, "Cryptographic Systems")
print(h.get(261), h.get(262))
h.remove(261)
print(h.get(261), h.get(262))
We see:
numpy