diff options
Diffstat (limited to 'packages/rtl-generics/src/generics.collections.pas')
-rw-r--r-- | packages/rtl-generics/src/generics.collections.pas | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/rtl-generics/src/generics.collections.pas b/packages/rtl-generics/src/generics.collections.pas index 2d08a76e9b..930675a86a 100644 --- a/packages/rtl-generics/src/generics.collections.pas +++ b/packages/rtl-generics/src/generics.collections.pas @@ -679,7 +679,10 @@ type procedure ValueNotify(constref AValue: TValue; ACollectionNotification: TCollectionNotification); inline; procedure NodeNotify(ANode: PNode; ACollectionNotification: TCollectionNotification; ADispose: boolean); inline; procedure SetValue(var AValue: TValue; constref ANewValue: TValue); + function GetItem(const AKey: TKey): TValue; + procedure SetItem(const AKey: TKey; const AValue: TValue); + property Items[Index: TKey]: TValue read GetItem write SetItem; // for reporting procedure WriteStr(AStream: TStream; const AText: string); public type @@ -782,6 +785,8 @@ type end; TAVLTreeMap<TKey, TValue> = class(TCustomAVLTreeMap<TKey, TValue, TEmptyRecord>) + public + property Items; default; end; TIndexedAVLTreeMap<TKey, TValue> = class(TCustomAVLTreeMap<TKey, TValue, SizeInt>) @@ -808,6 +813,7 @@ type protected property OnKeyNotify; property OnValueNotify; + property Items; public type TItemEnumerator = TKeyEnumerator; public @@ -3319,6 +3325,21 @@ begin Result := TValueCollection(FValues); end; +function TCustomAVLTreeMap<TREE_CONSTRAINTS>.GetItem(const AKey: TKey): TValue; +var + LNode: PNode; +begin + LNode := Find(AKey); + if not Assigned(LNode) then + raise EAVLTree.CreateRes(@SDictionaryKeyDoesNotExist); + result := LNode.Value; +end; + +procedure TCustomAVLTreeMap<TREE_CONSTRAINTS>.SetItem(const AKey: TKey; const AValue: TValue); +begin + Find(AKey).Value := AValue; +end; + constructor TCustomAVLTreeMap<TREE_CONSTRAINTS>.Create; begin FComparer := TComparer<TKey>.Default; |