Skip to content

Commit 1bb5e23

Browse files
authored
Merge pull request #315 from RodrigoDLPontes/quad-probing-resize
fix probing resize issue
2 parents 5f49288 + 2af90f1 commit 1bb5e23

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/algo/ClosedHash.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ export default class ClosedHash extends Hash {
8282

8383
this.hashTypeLabel = addLabelToAlgorithmBar('Hash Type:', this.dropDownLabelGroup);
8484
this.hashTypeDropDown = addDropDownGroupToAlgorithmBar(
85-
[['Integers', 'Hash Integers'], ['Strings', 'Hash Strings'], ['True', 'True Hash Function']],
85+
[
86+
['Integers', 'Hash Integers'],
87+
['Strings', 'Hash Strings'],
88+
['True', 'True Hash Function'],
89+
],
8690
'Hash Type',
8791
this.dropDownParentGroup,
8892
);

src/algo/OpenHash.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export default class OpenHash extends Hash {
8787
this.probeTypeDropDown.style.width = '132px';
8888
this.probeTypeDropDown.onchange = this.checkProbeType.bind(this);
8989

90-
9190
addDivisorToAlgorithmBar();
9291

9392
this.hashTypeParentGroup = addGroupToAlgorithmBar(false);
@@ -96,7 +95,11 @@ export default class OpenHash extends Hash {
9695

9796
this.hashTypeLabel = addLabelToAlgorithmBar('Hash Type:', this.hashTypeLabelGroup);
9897
this.hashTypeDropDown = addDropDownGroupToAlgorithmBar(
99-
[['Integers', 'Hash Integers'], ['Strings', 'Hash Strings'], ['True', 'True Hash Function']],
98+
[
99+
['Integers', 'Hash Integers'],
100+
['Strings', 'Hash Strings'],
101+
['True', 'True Hash Function'],
102+
],
100103
'Hash Type',
101104
this.hashTypedropDownGroup,
102105
);
@@ -179,7 +182,6 @@ export default class OpenHash extends Hash {
179182
const entry = new MapEntry(key, value);
180183
const elem = entry.elem;
181184
this.commands = [];
182-
183185
if (
184186
(this.size + 1) / this.table_size > this.load_factor &&
185187
this.table_size * 2 + 1 < MAX_SIZE
@@ -195,6 +197,8 @@ export default class OpenHash extends Hash {
195197

196198
if (index === -2 && this.table_size * 2 < MAX_SIZE) {
197199
this.resize(true);
200+
index = this.doHash(key);
201+
index = this.getEmptyIndex(index, key);
198202
} else if (index === -2) {
199203
this.cmd(
200204
act.setText,
@@ -447,8 +451,6 @@ export default class OpenHash extends Hash {
447451
}
448452

449453
resize(fromCycle) {
450-
this.commands = [];
451-
452454
this.cmd(act.setText, this.ExplainLabel, '');
453455
this.cmd(act.setText, this.DelIndexLabel, '');
454456

0 commit comments

Comments
 (0)