From 9a310c53b4a208c543e1dcc98736f413718b121f Mon Sep 17 00:00:00 2001 From: sunshinesDL <61528023+sunshinesDL@users.noreply.github.com> Date: Sun, 31 Aug 2025 17:25:30 +0800 Subject: [PATCH] Update array_hash_map.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 基于数组实现的哈希表中,`get()` 函数的返回值还可能会 None;且 `put()` 函数不仅可添加键值对、还可更新表中已有键值对的值; --- codes/python/chapter_hashing/array_hash_map.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codes/python/chapter_hashing/array_hash_map.py b/codes/python/chapter_hashing/array_hash_map.py index 945f44bb0a..e73973aa01 100644 --- a/codes/python/chapter_hashing/array_hash_map.py +++ b/codes/python/chapter_hashing/array_hash_map.py @@ -26,7 +26,7 @@ def hash_func(self, key: int) -> int: index = key % 100 return index - def get(self, key: int) -> str: + def get(self, key: int) -> str | None: """查询操作""" index: int = self.hash_func(key) pair: Pair = self.buckets[index] @@ -35,7 +35,7 @@ def get(self, key: int) -> str: return pair.val def put(self, key: int, val: str): - """添加操作""" + """添加和更新操作""" pair = Pair(key, val) index: int = self.hash_func(key) self.buckets[index] = pair