hashmapexample.pp 655 B

1234567891011121314151617181920212223242526272829303132333435
  1. {$mode objfpc}
  2. uses ghashmap;
  3. type hashlli=class
  4. public
  5. class function hash(a:longint; b:SizeUInt):SizeUInt;
  6. end;
  7. maplli=specialize THashMap<longint, longint, hashlli>;
  8. class function hashlli.hash(a:longint; b:SizeUInt):SizeUInt;
  9. begin
  10. hash:= a mod b;
  11. end;
  12. var data:maplli; i:longint; iterator:maplli.TIterator;
  13. begin
  14. data:=maplli.Create;
  15. for i:=0 to 10 do
  16. data[i] := 17*i;
  17. data.delete(5);
  18. {Iteration through elements}
  19. iterator:=data.Iterator;
  20. repeat
  21. writeln(iterator.Key, ' ', iterator.Value);
  22. until not iterator.Next;
  23. {Don't forget to destroy iterator}
  24. iterator.Destroy;
  25. data.Destroy;
  26. end.