hashmapexample.pp 632 B

1234567891011121314151617181920212223242526272829303132333435
  1. {$mode objfpc}
  2. {define oldstyleiterator}
  3. uses ghashmap;
  4. type hashlli=class
  5. public
  6. class function hash(a:longint; b:SizeUInt):SizeUInt;
  7. end;
  8. maplli=specialize THashMap<longint, longint, hashlli>;
  9. class function hashlli.hash(a:longint; b:SizeUInt):SizeUInt;
  10. begin
  11. hash:= a mod b;
  12. end;
  13. var data:maplli; i:longint;
  14. pair : maplli.TPair;
  15. begin
  16. data:=maplli.Create;
  17. for i:=0 to 10 do
  18. data[i] := 17*i;
  19. data.delete(5);
  20. {Iteration through elements}
  21. // destroying class iterators is afaik a FPC extension.
  22. for pair in data do
  23. writeln(pair.Key, ' ', pair.Value);
  24. data.Destroy;
  25. end.