On 13/04/2025 21:39, Michael Van Canneyt via fpc-devel wrote:
If keys could be accessed by index (the internal slot), the
TDictionary.IndexOfKey
and
TDictionary.Keys[idx]
That seems like a more 'conventional' solution to me.
I'll leave it up to you how to enhance TDictionary using either
solution...
Index may be misleading as it points to buckets, and they aren't
continuous.
FindBucketIndex is already protected. So I can call that from a subclass.
If I can add protected methods
Function GetKeyFromBucket: TKey;
Function GetDataFromBucket: TValue;
Or
Function GetItemFromBucket(idx: sizeint): TItem; // contains hash,key
and value
Function GetItemPtrFromBucket(idx: sizeint): PItem; // no need to copy
the content
The last one could be named GetMutableItemFromBucket.
Of course it has the issue that the slots for hash and key MUST NOT be
written.
So maybe the former 2 methods (getKeyFromBucket and GetValueFromBucket /
maybe GetMutableValueFromBucket).
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel