diff --git a/packages/fcl-stl/src/ghashmap.pp b/packages/fcl-stl/src/ghashmap.pp index 45458a31d2..eb6ae71d91 100644 --- a/packages/fcl-stl/src/ghashmap.pp +++ b/packages/fcl-stl/src/ghashmap.pp @@ -25,6 +25,7 @@ type generic THashmapIterator=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=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; diff --git a/packages/fcl-stl/src/gmap.pp b/packages/fcl-stl/src/gmap.pp index 71a38e9560..5de983a9d6 100644 --- a/packages/fcl-stl/src/gmap.pp +++ b/packages/fcl-stl/src/gmap.pp @@ -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=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; diff --git a/packages/fcl-stl/tests/ghashmaptest.pp b/packages/fcl-stl/tests/ghashmaptest.pp index 6a564e0db4..f3a487871f 100644 --- a/packages/fcl-stl/tests/ghashmaptest.pp +++ b/packages/fcl-stl/tests/ghashmaptest.pp @@ -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]); diff --git a/packages/fcl-stl/tests/gmaptest.pp b/packages/fcl-stl/tests/gmaptest.pp index ac903fc937..2e1136e853 100644 --- a/packages/fcl-stl/tests/gmaptest.pp +++ b/packages/fcl-stl/tests/gmaptest.pp @@ -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);