Hello,
I've some working code with a THashedStringList (was TStringList before) which is used to save a few hundreds of last inputs on my service. It's used to avoid double entries in a fast way with the hashing.
Now I was thinking about using a generic version like TDictionary for it as it has a better readability and I've read that you should better use generics if you write new code/do a refactoring.
So I'm adding my key=value pair to the THashedStringList as
Insert(0, key + '=' + value);
For cleanup I use the following code:
i := THashedStringList.Count - 1;
if i > 1000 then
begin
while i > 500 do
begin
THashedStringList.Delete(i);
i := THashedStringList.Count - 1;
end;
end;
For the key and value I do
i := IndexOfName(key);
value := ValueFromIndex[i];
But now my question, is there any equivalent version which uses generics where I can delete the oldest entries like I actually do?
I thought about using TDictionary<int id, TRecord<key,value>> but then I don't benefit from the hashing and have to think about the insertion of id. The same issue with hashing when I use a TList with TDictionary entries.
Thanks in advance!