[fpc-devel] 2 Ideas for generic TDictionary and other hash containers
Martin Frb
lazarus at mfriebe.de
Thu Mar 27 12:45:18 CET 2025
On 27/03/2025 12:33, Marco van de Voort via fpc-devel wrote:
>
> Op 27-3-2025 om 12:28 schreef Martin Frb via fpc-devel:
>>
>> which returns True, if Akey was found and therefore APtr points to
>> existing Data, while otherwise APtr points to the empty slot, where
>> the data can be copied to.
>>
> Without a key, you can't find the bucket or whatever where to
> allocate, so this is not possible for all dictionaries IMHO. IOW, it
> violates the contract with implementation details.
But in this feature, you always have the key.
You just don't have the data yet. You only create the data, if it does
not yet exist.
Its pretty much a
TryAdd.
But instead of having data, it adds "Default(TData)", and returns a
pointer to the mem.
Or, if the key existed, it returns a pointer to the existing data.
Of course the pointer is only valid, until the next operation on the
dict (or hash container).
It's just to save calculating the hash of the key twice.
More information about the fpc-devel
mailing list