is there a way to make the keys unique based on case? According to the LR, only non-ASCII characters (> 0x7F) are treated this way.
I need a dictionary that is insensitive regardless
myDict.value("ABC")=5
myDict.value("abc")=50
if I can’t do it with a dictionary, then I’ll have to resort to a slower array
Function myDict_CompareKeys(d As Xojo.Core.Dictionary, lhs As Auto, rhs As Auto) As Integer
Return CType(lhs, Text).Compare(rhs, Text.CompareCaseSensitive)
End Function
Travis, I am sorry, but I do not see such example in the Framework folder. The only dictionary example in Language Features is very basic an does not seem to contain any case sensitive method.
@Dave S : Why not EncodeBase64 your keys ? That would make them case sensitive. A subclass seems easy to do.
Function CreateCaseSensitiveDictionary() As Xojo.Core.Dictionary
return Xojo.Data.ParseJSON("{}")
End Function
// other place in code:
dim d as Xojo.Core.Dictionary = CreateCaseSensitiveDictionary
d.Value("name") = "John"
d.Value("Name") = "Jack"
Print d.Value("name")
Print d.Value("Name")
@Travis Hill , ah yes. That is nice. So just create a new class who’s super is xojo.Core.Dictionary, CaseSensitiveDictionary in the example. Then implement the CompareKeys event:
Dim lhsText As Text = lhs
Dim rhsText As Text = rhs
Dim value As Integer
value = lhsText.Compare(rhsText, Text.CompareCaseSensitive)
Return value
Interestingly enough, the Normal Dictionary is fastest, Dictionary from JSON is next and the CaseSensitiveDictionary that overrides the Event is the slowest, by far. Now, in normal use, probably will not matter. I created 100,000 random keys. Then inserted into each dictionary type, then did a lookup of each dictionary type… all the exact same pre-generated keys.
Results:
Normal Dictionary (Classic Framework)
Assign Keys: 107.2373ms
Get Keys: 65.26952ms
Dictionary from JSON (New Framework)
Assign Keys: 241.1384ms
Get Keys: 196.7326ms
CaseSensitiveDictionary (New Framework using Events)
Assign Keys: 590.029ms
Get Keys: 472.2623ms