fcl-stl THashMap iterator skips first element
Summary
It seems that when iterating through a THashMap (fcl-stl), one of the elements is always not returned.
System Information
- Operating system: Xubuntu GNU/Linux
- Processor architecture: x86-64
- Compiler version: 3.2.3
- Device: PC
Lazarus 2.2.7 (rev ada7a90f86) FPC 3.2.3 x86_64-linux-gtk2
Steps to reproduce
- Create a THashMap instance.
- Add 2 items to it
- Use a
forloop to iterate through it - Notice that only 1 item is returned
Example Project
program project1;
uses ghashmap;
type
{ TIntHashFunc }
TIntHashFunc = class
class function hash(a: Integer; n: SizeUInt): SizeUInt;
end;
TIntHash = specialize THashmap<Integer, Integer, TIntHashFunc>;
{ TIntHashFunc }
class function TIntHashFunc.hash(a: Integer; n: SizeUInt): SizeUInt;
begin
Result := a mod n;
end;
var
Hash: TIntHash;
Pair: TIntHash.TPair;
begin
Hash := TIntHash.Create;
Hash.insert(0, 5);
Hash.insert(1, 6);
for Pair in Hash do
writeln(pair.key, ' ', pair.value);
end.
Edited by Nick Faro