Skip to content

Commit 1e6a841

Browse files
authored
Update array_hash_map.py (#1803)
基于数组实现的哈希表中,`get()` 函数的返回值还可能会 None;且 `put()` 函数不仅可添加键值对、还可更新表中已有键值对的值;
1 parent 3709a97 commit 1e6a841

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

codes/python/chapter_hashing/array_hash_map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def hash_func(self, key: int) -> int:
2626
index = key % 100
2727
return index
2828

29-
def get(self, key: int) -> str:
29+
def get(self, key: int) -> str | None:
3030
"""查询操作"""
3131
index: int = self.hash_func(key)
3232
pair: Pair = self.buckets[index]
@@ -35,7 +35,7 @@ def get(self, key: int) -> str:
3535
return pair.val
3636

3737
def put(self, key: int, val: str):
38-
"""添加操作"""
38+
"""添加和更新操作"""
3939
pair = Pair(key, val)
4040
index: int = self.hash_func(key)
4141
self.buckets[index] = pair

0 commit comments

Comments
 (0)