What steps will reproduce the problem?
1. It always happens shCanGrow is executed in Add
What is the expected output? What do you see instead?
- The item hashed when shCanGrow is executed in Add cannot be found by the Find
function.
What version of the product are you using? On what operating system?
- 1.05a, but I checked the latest source here at google and the problem is
still there.
Please provide any additional information below.
- This is the fix: Simply move the hash calculation after the Grow, as below:
procedure TGpStringHash.Add(const key: string; value: integer);
var
bucket: PGpHashItem;
hash : cardinal;
begin
// LK 27 June 2010: The following line was here, but if the Grow is
// executed, then shNumBuckets gets changed and the hash used is wrong.
// So the next line has to be moved after the Grow.
//hash := HashOf(key) mod shNumBuckets;
if shFirstEmpty > shSize then
if shCanGrow then
Grow
else
raise Exception.Create('TGpStringHash.Add: Maximum size reached');
// LK 27 June 2010: Hash calculation moved here, and now it works.
hash := HashOf(key) mod shNumBuckets;
Original issue reported on code.google.com by lkess...@lkessler.com on 28 Jun 2010 at 5:00
Original issue reported on code.google.com by
lkess...@lkessler.com
on 28 Jun 2010 at 5:00