mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-19 21:49:25 +02:00
mutable value iterators fcl-stl
git-svn-id: trunk@17355 -
This commit is contained in:
parent
64c0fede25
commit
983c3633cd
@ -25,6 +25,7 @@
|
||||
type
|
||||
generic THashmapIterator<TKey, TValue, T, TTable>=class
|
||||
public
|
||||
type PValue=^TValue;
|
||||
var
|
||||
Fh,Fp:SizeUInt;
|
||||
FData:TTable;
|
||||
@ -32,10 +33,12 @@
|
||||
function GetData:T;inline;
|
||||
function GetKey:TKey;inline;
|
||||
function GetValue:TValue;inline;
|
||||
function GetMutable:PValue;inline;
|
||||
procedure SetValue(value:TValue);inline;
|
||||
property Data:T read GetData;
|
||||
property Key:TKey read GetKey;
|
||||
property Value:TValue read GetValue write SetValue;
|
||||
property MutableValue:PValue read GetMutable;
|
||||
end;
|
||||
|
||||
generic THashmap<TKey, TValue, Thash>=class
|
||||
@ -164,7 +167,7 @@ begin
|
||||
inc(FDataSize);
|
||||
(FData[h]).pushback(pair);
|
||||
|
||||
if (FDataSize > 2*FData.size) then
|
||||
if (FDataSize > 5*FData.size) then
|
||||
EnlargeTable;
|
||||
end;
|
||||
|
||||
@ -229,6 +232,11 @@ begin
|
||||
GetValue:=((FData[Fh])[Fp]).Value;
|
||||
end;
|
||||
|
||||
function THashmapIterator.GetMutable:PValue;inline;
|
||||
begin
|
||||
GetMutable:=@((FData[Fh]).Mutable[Fp]^.Value);
|
||||
end;
|
||||
|
||||
procedure THashmapIterator.SetValue(value:TValue);inline;
|
||||
begin
|
||||
((FData[Fh]).mutable[Fp])^.Value := value;
|
||||
|
@ -27,15 +27,18 @@ type
|
||||
public
|
||||
type PNode=^TNode;
|
||||
var FNode:PNode;
|
||||
type PValue=^TValue;
|
||||
function GetData:TPair;inline;
|
||||
function GetKey:TKey;inline;
|
||||
function GetValue:TValue;inline;
|
||||
function GetMutable:PValue;inline;
|
||||
procedure SetValue(value:TValue);inline;
|
||||
function Next:boolean;inline;
|
||||
function Prev:boolean;inline;
|
||||
property Data:TPair read GetData;
|
||||
property Key:TKey read GetKey;
|
||||
property Value:TValue read GetValue write SetValue;
|
||||
property MutableValue:PValue read GetMutable;
|
||||
end;
|
||||
|
||||
generic TMap<TKey, TValue, TCompare>=class
|
||||
@ -227,6 +230,11 @@ begin
|
||||
GetValue:=FNode^.Data.Value;
|
||||
end;
|
||||
|
||||
function TMapIterator.GetMutable:PValue;inline;
|
||||
begin
|
||||
GetMutable:=@(FNode^.Data.Value);
|
||||
end;
|
||||
|
||||
procedure TMapIterator.SetValue(value:TValue);inline;
|
||||
begin
|
||||
FNode^.Data.Value := value;
|
||||
|
@ -87,6 +87,8 @@ begin
|
||||
it.Value := it.Key+23;
|
||||
it.Value := it.Value*2;
|
||||
AssertEquals('bad value3', it.Key*2+46, it.Value);
|
||||
it.MutableValue^ := 222;
|
||||
AssertEquals('bad value4', 222, it.Value);
|
||||
until not it.next;
|
||||
for i:=0 to 1000 do begin
|
||||
AssertEquals('som not 1', 1, x[i]);
|
||||
|
@ -56,6 +56,8 @@ begin
|
||||
AssertEquals('Wrong next value', 5, it.Value);
|
||||
it.Value := it.Value + 17;
|
||||
AssertEquals('Wrong value update', 22, it.Value);
|
||||
it.MutableValue^:= 444;
|
||||
AssertEquals('Wrong mutable value update', 444, it.Value);
|
||||
AssertEquals('Next not true', true, it.Next);
|
||||
AssertEquals('Wrong next', 7, it.GetData.key);
|
||||
AssertEquals('Next not true', true, it.Next);
|
||||
|
Loading…
Reference in New Issue
Block a user