mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-10 10:09:21 +02:00
new examples for fcl-stl
git-svn-id: trunk@19053 -
This commit is contained in:
parent
fd908a70f1
commit
76b511bec5
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -2328,6 +2328,8 @@ packages/fcl-stl/Makefile.fpc svneol=native#text/plain
|
||||
packages/fcl-stl/doc/arrayutils.tex svneol=native#text/plain
|
||||
packages/fcl-stl/doc/deque.tex svneol=native#text/plain
|
||||
packages/fcl-stl/doc/dequeexample.pp svneol=native#text/plain
|
||||
packages/fcl-stl/doc/hashmapexample.pp svneol=native#text/plain
|
||||
packages/fcl-stl/doc/hashsetexample.pp svneol=native#text/plain
|
||||
packages/fcl-stl/doc/main.tex svneol=native#text/plain
|
||||
packages/fcl-stl/doc/makra.tex svneol=native#text/plain
|
||||
packages/fcl-stl/doc/map.tex svneol=native#text/plain
|
||||
|
35
packages/fcl-stl/doc/hashmapexample.pp
Normal file
35
packages/fcl-stl/doc/hashmapexample.pp
Normal file
@ -0,0 +1,35 @@
|
||||
{$mode objfpc}
|
||||
|
||||
uses ghashmap;
|
||||
|
||||
type hashlli=class
|
||||
public
|
||||
class function hash(a:longint; b:SizeUInt):SizeUInt;
|
||||
end;
|
||||
maplli=specialize THashMap<longint, longint, hashlli>;
|
||||
|
||||
class function hashlli.hash(a:longint; b:SizeUInt):SizeUInt;
|
||||
begin
|
||||
hash:= a mod b;
|
||||
end;
|
||||
|
||||
var data:maplli; i:longint; iterator:maplli.TIterator;
|
||||
|
||||
begin
|
||||
data:=maplli.Create;
|
||||
|
||||
for i:=0 to 10 do
|
||||
data[i] := 17*i;
|
||||
|
||||
data.delete(5);
|
||||
|
||||
{Iteration through elements}
|
||||
iterator:=data.Iterator;
|
||||
repeat
|
||||
writeln(iterator.Key, ' ', iterator.Value);
|
||||
until not iterator.Next;
|
||||
{Don't forget to destroy iterator}
|
||||
iterator.Destroy;
|
||||
|
||||
data.Destroy;
|
||||
end.
|
33
packages/fcl-stl/doc/hashsetexample.pp
Normal file
33
packages/fcl-stl/doc/hashsetexample.pp
Normal file
@ -0,0 +1,33 @@
|
||||
{$mode objfpc}
|
||||
|
||||
uses ghashset;
|
||||
|
||||
type hashlli=class
|
||||
public
|
||||
class function hash(a:longint; b:SizeUInt):SizeUInt;
|
||||
end;
|
||||
setlli=specialize THashSet<longint, hashlli>;
|
||||
|
||||
class function hashlli.hash(a:longint; b:SizeUInt):SizeUInt;
|
||||
begin
|
||||
hash:= a mod b;
|
||||
end;
|
||||
|
||||
var data:setlli; i:longint; iterator:setlli.TIterator;
|
||||
|
||||
begin
|
||||
data:=setlli.Create;
|
||||
|
||||
for i:=0 to 10 do
|
||||
data.insert(i);
|
||||
|
||||
{Iteration through elements}
|
||||
iterator:=data.Iterator;
|
||||
repeat
|
||||
writeln(iterator.Data);
|
||||
until not iterator.Next;
|
||||
{Don't forget to destroy iterator}
|
||||
iterator.Destroy;
|
||||
|
||||
data.Destroy;
|
||||
end.
|
@ -2,7 +2,8 @@ uses garrayutils, gutil, gvector;
|
||||
|
||||
type vectorlli = specialize TVector<longint>;
|
||||
lesslli = specialize TLess<longint>;
|
||||
sortlli = specialize TOrderingArrayUtils<vectorlli, longint, lesslli>;
|
||||
sortlli = specialize
|
||||
TOrderingArrayUtils<vectorlli, longint, lesslli>;
|
||||
|
||||
var data:vectorlli; n,i:longint;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user