mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 17:09:16 +02:00
rtl-generics: new examples for THashSet collection
git-svn-id: trunk@38600 -
This commit is contained in:
parent
7a7e09982b
commit
64297e9c96
8
.gitattributes
vendored
8
.gitattributes
vendored
@ -7406,6 +7406,14 @@ packages/rtl-generics/examples/thashmapcaseinsensitive/thashmapcaseinsensitive.l
|
|||||||
packages/rtl-generics/examples/thashmapcaseinsensitive/thashmapcaseinsensitive.lpr svneol=native#text/pascal
|
packages/rtl-generics/examples/thashmapcaseinsensitive/thashmapcaseinsensitive.lpr svneol=native#text/pascal
|
||||||
packages/rtl-generics/examples/thashmapextendedequalitycomparer/thashmapextendedequalitycomparer.lpi svneol=native#text/xml
|
packages/rtl-generics/examples/thashmapextendedequalitycomparer/thashmapextendedequalitycomparer.lpi svneol=native#text/xml
|
||||||
packages/rtl-generics/examples/thashmapextendedequalitycomparer/thashmapextendedequalitycomparer.lpr svneol=native#text/pascal
|
packages/rtl-generics/examples/thashmapextendedequalitycomparer/thashmapextendedequalitycomparer.lpr svneol=native#text/pascal
|
||||||
|
packages/rtl-generics/examples/thashset/thashset_exceptwith.lpi svneol=native#text/xml
|
||||||
|
packages/rtl-generics/examples/thashset/thashset_exceptwith.lpr svneol=native#text/pascal
|
||||||
|
packages/rtl-generics/examples/thashset/thashset_intersectwith.lpi svneol=native#text/xml
|
||||||
|
packages/rtl-generics/examples/thashset/thashset_intersectwith.lpr svneol=native#text/pascal
|
||||||
|
packages/rtl-generics/examples/thashset/thashset_symmetricexceptwith.lpi svneol=native#text/xml
|
||||||
|
packages/rtl-generics/examples/thashset/thashset_symmetricexceptwith.lpr svneol=native#text/pascal
|
||||||
|
packages/rtl-generics/examples/thashset/thashset_unionwith.lpi svneol=native#text/xml
|
||||||
|
packages/rtl-generics/examples/thashset/thashset_unionwith.lpr svneol=native#text/pascal
|
||||||
packages/rtl-generics/examples/tobjectlist/tobjectlistproject.lpi svneol=native#text/xml
|
packages/rtl-generics/examples/tobjectlist/tobjectlistproject.lpi svneol=native#text/xml
|
||||||
packages/rtl-generics/examples/tobjectlist/tobjectlistproject.lpr svneol=native#text/pascal
|
packages/rtl-generics/examples/tobjectlist/tobjectlistproject.lpr svneol=native#text/pascal
|
||||||
packages/rtl-generics/examples/tqueue/tqueueproject.lpi svneol=native#text/xml
|
packages/rtl-generics/examples/tqueue/tqueueproject.lpi svneol=native#text/xml
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="10"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<Title Value="thashset_exceptwith"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
</General>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<local>
|
||||||
|
<FormatVersion Value="1"/>
|
||||||
|
</local>
|
||||||
|
</RunParams>
|
||||||
|
<Units Count="1">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="thashset_exceptwith.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit0>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="thashset_exceptwith"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir);..\..\src\inc"/>
|
||||||
|
<OtherUnitFiles Value="..\..\src"/>
|
||||||
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
@ -0,0 +1,50 @@
|
|||||||
|
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.
|
||||||
|
|
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="10"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<Title Value="thashset_intersectwith"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
</General>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<local>
|
||||||
|
<FormatVersion Value="1"/>
|
||||||
|
</local>
|
||||||
|
</RunParams>
|
||||||
|
<Units Count="1">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="thashset_intersectwith.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit0>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="thashset_intersectwith"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir);..\..\src\inc"/>
|
||||||
|
<OtherUnitFiles Value="..\..\src"/>
|
||||||
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
@ -0,0 +1,53 @@
|
|||||||
|
program thashset_intersectwith;
|
||||||
|
|
||||||
|
{$MODE DELPHI}
|
||||||
|
{$APPTYPE CONSOLE}
|
||||||
|
|
||||||
|
uses
|
||||||
|
SysUtils, Generics.Collections;
|
||||||
|
|
||||||
|
function SetToStr(ASet: THashSet<string>): string;
|
||||||
|
var
|
||||||
|
i: string;
|
||||||
|
begin
|
||||||
|
Result := '(';
|
||||||
|
for i in ASet do
|
||||||
|
Result := Result + ' ' + i;
|
||||||
|
Result := Result + ' )';
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure WriteLnHashSet(const AName: string; AHashSet: THashSet<string>);
|
||||||
|
begin
|
||||||
|
WriteLn(Format('%0:s.Count = %1:d %0:s = %2:s', [AName, AHashSet.Count, SetToStr(AHashSet)]));
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
Group1: THashSet<string>;
|
||||||
|
Group2: THashSet<string>;
|
||||||
|
Group3: THashSet<string>;
|
||||||
|
begin
|
||||||
|
Group1 := THashSet<string>.Create;
|
||||||
|
Group2 := THashSet<string>.Create;
|
||||||
|
|
||||||
|
Group1.Add('User1');
|
||||||
|
Group1.Add('User2');
|
||||||
|
Group1.Add('User3');
|
||||||
|
Group2.Add('User3');
|
||||||
|
Group2.Add('User4');
|
||||||
|
Group2.Add('User5');
|
||||||
|
|
||||||
|
WriteLnHashSet('Group1', Group1);
|
||||||
|
WriteLnHashSet('Group2', Group2);
|
||||||
|
|
||||||
|
WriteLn('< Group3 IntersectWith Group2 >');
|
||||||
|
Group3 := THashSet<string>.Create(Group1);
|
||||||
|
Group3.IntersectWith(Group2);
|
||||||
|
WriteLnHashSet('Group3', Group3);
|
||||||
|
|
||||||
|
Group3.Free;
|
||||||
|
Group2.Free;
|
||||||
|
Group1.Free;
|
||||||
|
|
||||||
|
ReadLn;
|
||||||
|
end.
|
||||||
|
|
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="10"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<Title Value="thashset_symmetricexceptwith"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
</General>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<local>
|
||||||
|
<FormatVersion Value="1"/>
|
||||||
|
</local>
|
||||||
|
</RunParams>
|
||||||
|
<Units Count="1">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="thashset_symmetricexceptwith.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit0>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="thashset_symmetricexceptwith"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir);..\..\src\inc"/>
|
||||||
|
<OtherUnitFiles Value="..\..\src"/>
|
||||||
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
@ -0,0 +1,50 @@
|
|||||||
|
program thashset_symmetricexceptwith;
|
||||||
|
|
||||||
|
{$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 SymmetricExceptWith LowNumbers >');
|
||||||
|
HighNumbers.SymmetricExceptWith(LowNumbers);
|
||||||
|
WriteLnHashSet('HighNumbers', HighNumbers);
|
||||||
|
|
||||||
|
HighNumbers.Free;
|
||||||
|
LowNumbers.Free;
|
||||||
|
|
||||||
|
ReadLn;
|
||||||
|
end.
|
||||||
|
|
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="10"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<Title Value="thashset_unionwith"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
</General>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<local>
|
||||||
|
<FormatVersion Value="1"/>
|
||||||
|
</local>
|
||||||
|
</RunParams>
|
||||||
|
<Units Count="1">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="thashset_unionwith.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit0>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="thashset_unionwith"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir);..\..\src\inc"/>
|
||||||
|
<OtherUnitFiles Value="..\..\src"/>
|
||||||
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
@ -0,0 +1,53 @@
|
|||||||
|
program thashset_unionwith;
|
||||||
|
|
||||||
|
{$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
|
||||||
|
EvenNumbers: THashSet<Integer>;
|
||||||
|
OddNumbers: THashSet<Integer>;
|
||||||
|
Numbers: THashSet<Integer>;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
EvenNumbers := THashSet<Integer>.Create;
|
||||||
|
OddNumbers := THashSet<Integer>.Create;
|
||||||
|
|
||||||
|
for i := 0 to 4 do
|
||||||
|
begin
|
||||||
|
EvenNumbers.Add(i * 2);
|
||||||
|
OddNumbers.Add((i * 2) + 1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
WriteLnHashSet('EvenNumbers', EvenNumbers);
|
||||||
|
WriteLnHashSet('OddNumbers', OddNumbers);
|
||||||
|
|
||||||
|
WriteLn('< Numbers UnionWith OddNumbers >');
|
||||||
|
Numbers := THashSet<Integer>.Create(EvenNumbers);
|
||||||
|
Numbers.UnionWith(OddNumbers);
|
||||||
|
WriteLnHashSet('Numbers', Numbers);
|
||||||
|
|
||||||
|
Numbers.Free;
|
||||||
|
OddNumbers.Free;
|
||||||
|
EvenNumbers.Free;
|
||||||
|
|
||||||
|
ReadLn;
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user