mapexample.pp 821 B

12345678910111213141516171819202122232425262728293031323334
  1. uses gmap, gutil;
  2. type lesslli=specialize TLess<longint>;
  3. maplli=specialize TMap<longint, longint, lesslli>;
  4. var data:maplli; i:longint; iterator:maplli.TIterator;
  5. pair : maplli.TPair;
  6. begin
  7. data:=maplli.Create;
  8. for i:=0 to 10 do
  9. data[i]:=10*i;
  10. writeln(data[7]);
  11. data[7] := 42;
  12. {Iteration through elements with write access}
  13. iterator:=data.Min;
  14. repeat
  15. writeln(iterator.Key, ' ', iterator.Value);
  16. iterator.Value := 47;
  17. until not iterator.next;
  18. iterator.Destroy;
  19. // using for..in to check everything changed to 47. For in is shorter and autoallocated, but can't write to cells via iterator.
  20. for pair in data.min do
  21. writeln('Min: ',pair.Key, ' ', pair.Value);
  22. iterator := data.FindLess(7);
  23. writeln(iterator.Value);
  24. iterator.Destroy;
  25. data.Destroy;
  26. end.