Does anyone know if a TreeMap structure is available in Delphi 10.2 ?

Does anyone know if a TreeMap structure is available in Delphi 10.2 ?

I am looking for that kind of structure mainly to be able to answer this question : "Which element in this collection is the closest to this one?".

Comments

  1. Rfk ALN If there is any room for optimizing any of the IEnumerable methods for a specific collection then report an issue and I will look into it. For this particular issue keep in mind though that when you pass a predicate this cannot work on binary search. Binary search works on the criteria the items are sorted on.

    ReplyDelete
  2. Stefan Glienke Thank you. Ok I know understand how the predicate works. If I sum-up correctly : when I am using the method First with a predicate you will first sort the collection then you will be able to return the first item that correponds to my predicate, is that right ?

    ReplyDelete
  3. Rfk ALN No, First with predicate will do a linear search in all cases as it cannot look into the predicate what it checks for as that is a compiled anonymous method. If you want fast lookup based on some key, then store the items in an according structure (any of the dictionaries or maps we have). If you already have any other existing collection you can pass it to the TEnumerable.ToLookup method specifying a key selector and it returns an ILookup interface which is like a readonly dictionary.

    ReplyDelete

Post a Comment