OpenHash: findElement() may report wrong value
Closed this issue · 0 comments
piater commented
In OpenHash.js
, findElement()
contains these lines of code:
const found = this.getElemIndex(index, key) !== -1;
if (found) {
this.cmd(
act.setText,
this.ExplainLabel,
'Found Key: ' + key + ' Value: ' + this.hashTableValues[index].val,
If the key
is found, the value at index
is reported. However, index
is the result of the hash function of the key
; this table cell may be occupied by a colliding key. The correct solution is to use the return value of getElemIndex()
:
const found = this.getElemIndex(index, key);
if (found !== -1) {
this.cmd(
act.setText,
this.ExplainLabel,
'Found Key: ' + key + ' Value: ' + this.hashTableValues[found].val,