revalNG / omnithreadlibrary

Automatically exported from code.google.com/p/omnithreadlibrary
0 stars 0 forks source link

Hash calculated in Add is not correct when Grow happens #20

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
Thanks for a) finding the problem and b) fixing it! Your fix was committed.

Original comment by gabr42 on 28 Jun 2010 at 12:48