Monkey
Store
Community
Apps
Contact
Login or Signup

Maps of Int[]

Monkey Programming Forums/Monkey Programming/Maps of Int[]

dmaz(Posted 1+ years ago) #1
I can't seem to declare a map of an array of ints... in BMax you could int arrays in maps no problem but in monkey I've had no luck.

I've tried:
Local amap:StringMap<Int[]> = New StringMap<Int[]>
(syntax error - expecting identifier)

Local amap:StringMap<IntObject[]> = New StringMap<IntObject[]>
(syntax error - expecting '>')

Local amap:Map<String,Int[]> = New Map<String,Int[]>
(syntax error - expecting identifier)

any ideas?


slenkar(Posted 1+ years ago) #2
try local i:IntMap=new IntMap ?

EDIT oh an array, hmm dont know if its possible


GfK(Posted 1+ years ago) #3
You could always wrap the Int array in a class. That should work.


dmaz(Posted 1+ years ago) #4
yeah, I suppose I will have to do that.


Samah(Posted 1+ years ago) #5
See: http://monkeycoder.co.nz/Community/post.php?topic=1408&post=12717

Your best bet is:
Local mymap:StringMap<List<IntObject>> = New StringMap<List<IntObject>>



dmaz(Posted 1+ years ago) #6
thanks, List won't work since I need array indexing... but Stack would. I'm going to go with a custom class though.


Samah(Posted 1+ years ago) #7
Use Diddy's ArrayList classes then.

Import diddy

Function Main:Int()
	Local mymap:StringMap<IntArrayList> = New StringMap<IntArrayList>
	mymap.Set("foo", New IntArrayList)
	mymap.Get("foo").Add(42)
	Print mymap.Get("foo").Get(0)
End