It is currently Thu Aug 06, 2020 11:18 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Map keys behave differently between PB and SB
PostPosted: Mon May 25, 2020 3:24 pm 
Offline
User
User
User avatar

Joined: Fri Nov 02, 2007 6:37 pm
Posts: 14
Location: Canada
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:

Code:
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


SpiderBasic output:

Code:
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


PureBasic output:
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Map keys behave differently between PB and SB
PostPosted: Mon May 25, 2020 3:27 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14065
Location: France
True. It can also change if we implement a better algorythm in PB, you shouldn't rely on that.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 27 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye