Xojo.Core.DictionaryEntry Question

We were always told not to rely upon the order of objects in the old Dictionary object. But, it seemed for the most part, it was repeatable.

From what I can tell from Xojo.Core.Dictionary it seems like order is practically randomized. I’m assuming this was done on purpose and that if you want the Dictionary to be in some order, or sorted, you have to implement the CompareKeys event. Is that correct?

with any hash map, it should be that order is stable unless you change it.

If you want the dictionary to be in some order, you’ll need to keep a separate array of what the ordered keys are. The dictionary itself has no guaranteed ordering, even when CompareKeys is used.

Hhmmmm…then what is the point of the CompareKeys event? Seems kind of useless then.

It allows you to customize key-value lookup by controlling what keys are equal to what other keys. A simple example is making a dictionary that uses case-sensitive keys. For example:

Function CompareKeys(lhs As Auto, rhs As Auto) As Integer Handles Event Return CType(lhs, Text).Compare(rhs, Text.CompareCaseSensitive) End Function