This commit is contained in:
krahets
2023-10-04 02:44:58 +08:00
parent 49ad0a6422
commit b3956c9e88
3 changed files with 7 additions and 6 deletions
+5 -5
View File
@@ -59,7 +59,7 @@ comments: true
"""负载因子"""
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]
@@ -167,8 +167,8 @@ comments: true
return pair->val;
}
}
// 若未找到 key 则返回 nullptr
return nullptr;
// 若未找到 key 则返回空字符串
return "";
}
/* 添加操作 */
@@ -386,7 +386,7 @@ comments: true
}
/* 查询操作 */
public string get(int key) {
public string? get(int key) {
int index = hashFunc(key);
// 遍历桶,若找到 key 则返回对应 val
foreach (Pair pair in buckets[index]) {
@@ -1792,7 +1792,7 @@ comments: true
}
/* 查询操作 */
public string get(int key) {
public string? get(int key) {
// 搜索 key 对应的桶索引
int index = findBucket(key);
// 若找到键值对,则返回对应 val