fix(Rust): no need to clone in hash put fn (#1226)

* no need to clone in hash put fn

* fmt rust code

* make code more readable

* Change vec append to extend, more friendly to rookie rust dev

* drop comment
This commit is contained in:
rongyi
2024-04-07 14:46:21 +08:00
committed by GitHub
parent bd54594a90
commit f901a31bae
4 changed files with 16 additions and 18 deletions
@@ -102,17 +102,14 @@ impl HashMapChaining {
// 遍历桶,若遇到指定 key ,则更新对应 val 并返回
for pair in bucket {
if pair.key == key {
pair.val = val.clone();
pair.val = val;
return;
}
}
let bucket = &mut self.buckets[index];
// 若无该 key ,则将键值对添加至尾部
let pair = Pair {
key,
val: val.clone(),
};
let pair = Pair { key, val };
bucket.push(pair);
self.size += 1;
}