mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
Several bug fixes.
This commit is contained in:
@@ -47,7 +47,7 @@ class ArrayHashMap {
|
||||
int index = hashFunc(key);
|
||||
Pair *pair = buckets[index];
|
||||
if (pair == nullptr)
|
||||
return nullptr;
|
||||
return "";
|
||||
return pair->val;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ class HashMapChaining {
|
||||
return pair->val;
|
||||
}
|
||||
}
|
||||
// 若未找到 key 则返回 nullptr
|
||||
return nullptr;
|
||||
// 若未找到 key 则返回空字符串
|
||||
return "";
|
||||
}
|
||||
|
||||
/* 添加操作 */
|
||||
|
||||
@@ -37,7 +37,7 @@ class HashMapChaining {
|
||||
}
|
||||
|
||||
/* 查询操作 */
|
||||
public string get(int key) {
|
||||
public string? get(int key) {
|
||||
int index = hashFunc(key);
|
||||
// 遍历桶,若找到 key 则返回对应 val
|
||||
foreach (Pair pair in buckets[index]) {
|
||||
|
||||
@@ -59,7 +59,7 @@ class HashMapOpenAddressing {
|
||||
}
|
||||
|
||||
/* 查询操作 */
|
||||
public string get(int key) {
|
||||
public string? get(int key) {
|
||||
// 搜索 key 对应的桶索引
|
||||
int index = findBucket(key);
|
||||
// 若找到键值对,则返回对应 val
|
||||
|
||||
@@ -29,7 +29,7 @@ class HashMapChaining:
|
||||
"""负载因子"""
|
||||
return self.size / self.capacity
|
||||
|
||||
def get(self, key: int) -> str:
|
||||
def get(self, key: int) -> str | None:
|
||||
"""查询操作"""
|
||||
index = self.hash_func(key)
|
||||
bucket = self.buckets[index]
|
||||
|
||||
Reference in New Issue
Block a user