Map keys behave differently between PB and SB
Posted: Mon May 25, 2020 3:24 pm
It is not safe to assume that keys in the map are behaving in the same way when porting code forth and back between SpiderBasic and PureBasic.
Apparently SpiderBasic preserves map keys in order of populating while PureBasic does something else (likely some hashing for speed optimization)
the code:
SpiderBasic output:
PureBasic output:
Apparently SpiderBasic preserves map keys in order of populating while PureBasic does something else (likely some hashing for speed optimization)
the code:
Code: Select all
Procedure.s makeword()
Protected.s word
Protected.i i
word = ""
For i = 1 To 5:
word + Chr(Random(90,65))
Next
ProcedureReturn word
EndProcedure
Global NewList myList.s()
Global NewMap myMap.s()
Global i
Global.s word
Debug "Populate"
For i = 1 To 10:
word = makeword()
Debug word
AddElement(myList())
myList() = word
AddMapElement(myMap(), word)
Next
Debug "List:"
ForEach myList()
Debug myList()
Next
Debug "Map:"
ForEach myMap()
Debug MapKey(myMap())
Next
Code: Select all
Populate
LTASV
GJMTS
JJIKJ
ATHOY
ZQSXC
JNFST
UFECP
KLJQQ
RYFRZ
ZHLYK
List:
LTASV
GJMTS
JJIKJ
ATHOY
ZQSXC
JNFST
UFECP
KLJQQ
RYFRZ
ZHLYK
Map:
LTASV
GJMTS
JJIKJ
ATHOY
ZQSXC
JNFST
UFECP
KLJQQ
RYFRZ
ZHLYK
Code: Select all
Populate
GLJPG
OBWPJ
QCDLB
TIMXS
YCWMJ
NPSKG
ZRNNL
AXGMG
YZWMQ
XMNYB
List:
GLJPG
OBWPJ
QCDLB
TIMXS
YCWMJ
NPSKG
ZRNNL
AXGMG
YZWMQ
XMNYB
Map:
ZRNNL
QCDLB
TIMXS
YZWMQ
AXGMG
GLJPG
XMNYB
OBWPJ
YCWMJ
NPSKG