mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-13 07:46:06 +00:00
Several bug fixes.
This commit is contained in:
@@ -48,7 +48,7 @@ hashMapChaining *newHashMapChaining() {
|
||||
hashmap->capacity = tableSize;
|
||||
hashmap->size = 0;
|
||||
hashmap->extendRatio = 2;
|
||||
hashmap->loadThres = 2.0 / 3;
|
||||
hashmap->loadThres = 2.0 / 3.0;
|
||||
|
||||
return hashmap;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class HashMapChaining {
|
||||
|
||||
public:
|
||||
/* 构造方法 */
|
||||
HashMapChaining() : size(0), capacity(4), loadThres(2.0 / 3), extendRatio(2) {
|
||||
HashMapChaining() : size(0), capacity(4), loadThres(2.0 / 3.0), extendRatio(2) {
|
||||
buckets.resize(capacity);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class HashMapOpenAddressing {
|
||||
private:
|
||||
int size; // 键值对数量
|
||||
int capacity = 4; // 哈希表容量
|
||||
const double loadThres = 2.0 / 3; // 触发扩容的负载因子阈值
|
||||
const double loadThres = 2.0 / 3.0; // 触发扩容的负载因子阈值
|
||||
const int extendRatio = 2; // 扩容倍数
|
||||
vector<Pair *> buckets; // 桶数组
|
||||
Pair *TOMBSTONE = new Pair(-1, "-1"); // 删除标记
|
||||
|
||||
@@ -18,7 +18,7 @@ class HashMapChaining {
|
||||
public HashMapChaining() {
|
||||
size = 0;
|
||||
capacity = 4;
|
||||
loadThres = 2 / 3.0;
|
||||
loadThres = 2.0 / 3.0;
|
||||
extendRatio = 2;
|
||||
buckets = new List<List<Pair>>(capacity);
|
||||
for (int i = 0; i < capacity; i++) {
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace hello_algo.chapter_hashing;
|
||||
class HashMapOpenAddressing {
|
||||
private int size; // 键值对数量
|
||||
private int capacity = 4; // 哈希表容量
|
||||
private double loadThres = 2.0 / 3; // 触发扩容的负载因子阈值
|
||||
private double loadThres = 2.0 / 3.0; // 触发扩容的负载因子阈值
|
||||
private int extendRatio = 2; // 扩容倍数
|
||||
private Pair[] buckets; // 桶数组
|
||||
private Pair TOMBSTONE = new Pair(-1, "-1"); // 删除标记
|
||||
|
||||
@@ -23,7 +23,7 @@ class HashMapChaining {
|
||||
HashMapChaining() {
|
||||
size = 0;
|
||||
capacity = 4;
|
||||
loadThres = 2 / 3.0;
|
||||
loadThres = 2.0 / 3.0;
|
||||
extendRatio = 2;
|
||||
buckets = List.generate(capacity, (_) => []);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func newHashMapChaining() *hashMapChaining {
|
||||
return &hashMapChaining{
|
||||
size: 0,
|
||||
capacity: 4,
|
||||
loadThres: 2 / 3.0,
|
||||
loadThres: 2.0 / 3.0,
|
||||
extendRatio: 2,
|
||||
buckets: buckets,
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func newHashMapOpenAddressing() *hashMapOpenAddressing {
|
||||
return &hashMapOpenAddressing{
|
||||
size: 0,
|
||||
capacity: 4,
|
||||
loadThres: 2 / 3.0,
|
||||
loadThres: 2.0 / 3.0,
|
||||
extendRatio: 2,
|
||||
buckets: buckets,
|
||||
removed: pair{
|
||||
|
||||
@@ -21,7 +21,7 @@ class HashMapChaining {
|
||||
public HashMapChaining() {
|
||||
size = 0;
|
||||
capacity = 4;
|
||||
loadThres = 2 / 3.0;
|
||||
loadThres = 2.0 / 3.0;
|
||||
extendRatio = 2;
|
||||
buckets = new ArrayList<>(capacity);
|
||||
for (int i = 0; i < capacity; i++) {
|
||||
|
||||
@@ -10,7 +10,7 @@ package chapter_hashing;
|
||||
class HashMapOpenAddressing {
|
||||
private int size; // 键值对数量
|
||||
private int capacity = 4; // 哈希表容量
|
||||
private final double loadThres = 2.0 / 3; // 触发扩容的负载因子阈值
|
||||
private final double loadThres = 2.0 / 3.0; // 触发扩容的负载因子阈值
|
||||
private final int extendRatio = 2; // 扩容倍数
|
||||
private Pair[] buckets; // 桶数组
|
||||
private final Pair TOMBSTONE = new Pair(-1, "-1"); // 删除标记
|
||||
|
||||
@@ -24,7 +24,7 @@ class HashMapChaining {
|
||||
constructor() {
|
||||
this.#size = 0;
|
||||
this.#capacity = 4;
|
||||
this.#loadThres = 2 / 3.0;
|
||||
this.#loadThres = 2.0 / 3.0;
|
||||
this.#extendRatio = 2;
|
||||
this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class HashMapChaining:
|
||||
"""构造方法"""
|
||||
self.size = 0 # 键值对数量
|
||||
self.capacity = 4 # 哈希表容量
|
||||
self.load_thres = 2 / 3 # 触发扩容的负载因子阈值
|
||||
self.load_thres = 2.0 / 3.0 # 触发扩容的负载因子阈值
|
||||
self.extend_ratio = 2 # 扩容倍数
|
||||
self.buckets = [[] for _ in range(self.capacity)] # 桶数组
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class HashMapOpenAddressing:
|
||||
"""构造方法"""
|
||||
self.size = 0 # 键值对数量
|
||||
self.capacity = 4 # 哈希表容量
|
||||
self.load_thres = 2 / 3 # 触发扩容的负载因子阈值
|
||||
self.load_thres = 2.0 / 3.0 # 触发扩容的负载因子阈值
|
||||
self.extend_ratio = 2 # 扩容倍数
|
||||
self.buckets: list[Pair | None] = [None] * self.capacity # 桶数组
|
||||
self.TOMBSTONE = Pair(-1, "-1") # 删除标记
|
||||
|
||||
@@ -18,7 +18,7 @@ class HashMapChaining {
|
||||
init() {
|
||||
size = 0
|
||||
capacity = 4
|
||||
loadThres = 2 / 3
|
||||
loadThres = 2.0 / 3.0
|
||||
extendRatio = 2
|
||||
buckets = Array(repeating: [], count: capacity)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class HashMapOpenAddressing {
|
||||
init() {
|
||||
size = 0
|
||||
capacity = 4
|
||||
loadThres = 2 / 3
|
||||
loadThres = 2.0 / 3.0
|
||||
extendRatio = 2
|
||||
buckets = Array(repeating: nil, count: capacity)
|
||||
removed = Pair(key: -1, val: "-1")
|
||||
|
||||
@@ -26,7 +26,7 @@ class HashMapChaining {
|
||||
constructor() {
|
||||
this.#size = 0;
|
||||
this.#capacity = 4;
|
||||
this.#loadThres = 2 / 3.0;
|
||||
this.#loadThres = 2.0 / 3.0;
|
||||
this.#extendRatio = 2;
|
||||
this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user