mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-25 23:36:30 +08:00
build
This commit is contained in:
parent
49ad0a6422
commit
b3956c9e88
3 changed files with 7 additions and 6 deletions
|
@ -37,6 +37,7 @@ index = hash(key) % capacity
|
|||
|
||||
对于密码学的相关应用,为了防止从哈希值推导出原始密码等逆向工程,哈希算法需要具备更高等级的安全特性。
|
||||
|
||||
- **单向性**:无法通过哈希值反推出关于输入数据的任何信息。
|
||||
- **抗碰撞性**:应当极其困难找到两个不同的输入,使得它们的哈希值相同。
|
||||
- **雪崩效应**:输入的微小变化应当导致输出的显著且不可预测的变化。
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -621,7 +621,7 @@ index = hash(key) % capacity
|
|||
int index = hashFunc(key);
|
||||
Pair *pair = buckets[index];
|
||||
if (pair == nullptr)
|
||||
return nullptr;
|
||||
return "";
|
||||
return pair->val;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue