2
0

thashset_exceptwith.lpr 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. program thashset_exceptwith;
  2. {$MODE DELPHI}
  3. {$APPTYPE CONSOLE}
  4. uses
  5. SysUtils, Generics.Collections;
  6. function SetToStr(ASet: THashSet<Integer>): string;
  7. var
  8. i: Integer;
  9. begin
  10. Result := '(';
  11. for i in ASet do
  12. Result := Result + ' ' + IntToStr(i);
  13. Result := Result + ' )';
  14. end;
  15. procedure WriteLnHashSet(const AName: string; AHashSet: THashSet<Integer>);
  16. begin
  17. WriteLn(Format('%0:s.Count = %1:d %0:s = %2:s', [AName, AHashSet.Count, SetToStr(AHashSet)]));
  18. end;
  19. var
  20. LowNumbers: THashSet<Integer>;
  21. HighNumbers: THashSet<Integer>;
  22. i: Integer;
  23. begin
  24. LowNumbers := THashSet<Integer>.Create;
  25. HighNumbers := THashSet<Integer>.Create;
  26. for i := 0 to 5 do
  27. LowNumbers.Add(i);
  28. for i := 3 to 9 do
  29. HighNumbers.Add(i);
  30. WriteLnHashSet('LowNumbers', LowNumbers);
  31. WriteLnHashSet('HighNumbers', HighNumbers);
  32. WriteLn('< HighNumbers ExceptWith LowNumbers >');
  33. HighNumbers.ExceptWith(LowNumbers);
  34. WriteLnHashSet('HighNumbers', HighNumbers);
  35. HighNumbers.Free;
  36. LowNumbers.Free;
  37. ReadLn;
  38. end.