Given that TDictionary
exposes only ways to retrieve value through the key, I have the following algorithm to fetch a key from its value:
var
Table: TDictionary<Int64, Extended>;
function KeyOf(Value: Extended): Int64; inline;
var
Key: Int64;
begin
Result := -1;
if not Table.ContainsValue(Value) then
Exit;
for Key in Table.Keys do
if Table.Items[Key] = Value then
begin
Result := Key;
Exit;
end;
end;
-
I'm calling this function in a loop that runs at least 50,000 times.
-
I need to keep indexing for non-repeating integers.
-
During execution, the structure will behave on average 50 items.
-
It would also be good to replace this structure with any other.
And so my question: is there a way to accomplish the same task with the best execution speed performance?