any basic with maps?

Started by meems, September 18, 2017, 19:37:07

Previous topic - Next topic

meems

is there any modern basic that has 'maps' ? i like em. First saw em in monkey.

explain why they are good :

many games are 2D cell based, e.g. gauntlet. so its natural to use a 2D array - > Dim cell(x,y). 2D arrays are compiled as 1D arrays  -> Dim cell(x*y)
One weakness of this is many cells are empty, a 2D cell map might have only 10% of its cells non-zero. Routines that effect cells can spend a lot of time checking these null cells.
A common basic alternative is to store active cells as objects in typedefs that contain the cell location. Then routines that effect active cells can run thru a list without null cells. But this method struggles with cell interactions, because instead of checking nearby cells for collision, a collision detector has to run thru all cells in the active cell list.
As far as I know there's no fast way to get round this in basic. There has to be some inefficient mix of 2D cell arrays and active cell lists.
Hence the need for 'maps'. Which are a cross between arrays and lists. A map is a list, which like an array can be fast referenced by its location \ key \ index but unlike arrays there doesn't have to be empty cells between active cells.

have anyone worked with maps and been able to compare their efficiency and speed with 2D array \ active cell list combos?

Xaron

I agree, I love maps as well and would like to integrate it (together with other containers) into our upcoming Basic language.

Maps are quite efficient. Where arrays are naturally very fast to access (complexity O(1)) they have some disadvantages when it comes to resizing and inserting stuff. Maps are almost that fast to access (O(1) as well!) but are much easier to expand both with inserting, "resizing" and all that stuff.

Steve Elliott

Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

sphinx

Kind regards,
Maher F. Farag
www.ancientsoft.com
www.osakit.com

MikeHart

I always considered Cerberus X to be a BASIC dialect and it has maps and other containers.

meems

>PureBasic!
Nice. blitzPlus doesn't have map. Never thought of pureBasic as a gaming language though. Any reason NOT to use pureBasic? Is there anything like a pros and cons table comparing all the current basics? Hopefully one will stand out from the rest.

>Cerberus X
Haven't looked at that yet. I thought it was a version of monkey. i.e. another language in the burning depths of OOP hell. Or is it functional basic?

TomToad

------------------------------------------------
8 rabbits equals 1 rabbyte.

Naughty Alien


sphinx

Quote>PureBasic!
Nice. blitzPlus doesn't have map. Never thought of pureBasic as a gaming language though. Any reason NOT to use pureBasic? Is there anything like a pros and cons table comparing all the current basics? Hopefully one will stand out from the rest.
It is multi platform but no mobile support, for HTML5 you can use its sister language SpiderBasic.
It has native GUI support for Windows, Mac and Linux.
It has 3D engine but I can not tell how good/bad it is as I did not use it.
Produces quit small and fast executable although the compiler is one pass hence very very fast compilation time!
It has many libraries for dealing with many things!
Kind regards,
Maher F. Farag
www.ancientsoft.com
www.osakit.com

GW

btw: maps are O(log n) for access/insert/delete, not O(1). 

Xaron

Actually not. O(log n) is true for trees. If the hash function is good, access/insert/delete for a map has indeed O(1) so constant time. You don't need to search in a tree.