Maps vs Lists

BlitzMax Forums/BlitzMax Beginners Area/Maps vs Lists

Ferret(Posted 2014) [#1]
I read somewhere that maps are faster then lists.

Is this true and always the case?


Derron(Posted 2014) [#2]
true and not always the case.


It - like everytime - depends on various cases.

Many inserts/removals/...

do you want to loop through a set or prefer direct access? Do you need Access by a GUID/key? ...

As soon as you want things to be only stored ONE time ... you should use TMap as it automatically has a 1:1 relation (key:object) while with TLists you need a "my.list.contains(obj)"-check to know whether you should addLast(obj) or better skip it (as it already exists).


If you do not need to access objects via a "key/GUID" and you also do not have to "order" them you might think of using arrays.


You can iterate over all of them, and all of them allow to limit the results to be of specific types

for local a:myobject = EachIn arr / list / map
... only valid "myobject"-objects are returned
next


bye
Ron


Ferret(Posted 2014) [#3]
Very helpful, thx!