1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- program thashset_exceptwith;
- {$MODE DELPHI}
- {$APPTYPE CONSOLE}
- uses
- SysUtils, Generics.Collections;
- function SetToStr(ASet: THashSet<Integer>): string;
- var
- i: Integer;
- begin
- Result := '(';
- for i in ASet do
- Result := Result + ' ' + IntToStr(i);
- Result := Result + ' )';
- end;
- procedure WriteLnHashSet(const AName: string; AHashSet: THashSet<Integer>);
- begin
- WriteLn(Format('%0:s.Count = %1:d %0:s = %2:s', [AName, AHashSet.Count, SetToStr(AHashSet)]));
- end;
- var
- LowNumbers: THashSet<Integer>;
- HighNumbers: THashSet<Integer>;
- i: Integer;
- begin
- LowNumbers := THashSet<Integer>.Create;
- HighNumbers := THashSet<Integer>.Create;
- for i := 0 to 5 do
- LowNumbers.Add(i);
- for i := 3 to 9 do
- HighNumbers.Add(i);
- WriteLnHashSet('LowNumbers', LowNumbers);
- WriteLnHashSet('HighNumbers', HighNumbers);
- WriteLn('< HighNumbers ExceptWith LowNumbers >');
- HighNumbers.ExceptWith(LowNumbers);
- WriteLnHashSet('HighNumbers', HighNumbers);
- HighNumbers.Free;
- LowNumbers.Free;
- ReadLn;
- end.
|