StringMap? Map? FloatMap? IntMap?

Monkey Forums/Monkey Programming/StringMap? Map? FloatMap? IntMap?

GfK(Posted 2011) [#1]
Documentation on these is... scarce, shall we say.

What's the difference between the above? I'm assuming that it pertains to the format of the Key but I can't find any info.


Raz(Posted 2011) [#2]
yeah a stringmap uses a string as its index and like for like with the others.
_screenlist:Stringmap<Screen> = New Stringmap<Screen>
_screenlist.Set("main",new MainScreen())
activescreen:Screen = _screenlist.Get("main")


Warpy(Posted 2011) [#3]
Because monkey's type system is a lot stricter than Bmax's (to put it simply) and doesn't have a generic compare method built in, you need to specify the type of the keys for a map and extend the Map type to define a compare method. StringMap, FloatMap, IntMap, etc. do this for you.

If you wanted to make a map with a different type of object as a key, you can't just use the map type - you've got to extend it and provide a compare method.

This is dealt with in other languages by providing interfaces, and I've forgotten where Mark is up to with those in monkey.


muddy_shoes(Posted 2011) [#4]
This is dealt with in other languages by providing interfaces, and I've forgotten where Mark is up to with those in monkey.


Interfaces are in the language but aren't utilised in the collections library design. I imagine that most people engaged in significant projects have ended up writing their versions of IComparable/IComparator and collections of their own if they have a need to sort or search using custom classes.


Warpy(Posted 2011) [#5]
I can remember having a look at doing that when interfaces first appeared, but something stopped me. I can't remember what.


Samah(Posted 2011) [#6]
Interfaces are in the language but aren't utilised in the collections library design. I imagine that most people engaged in significant projects have ended up writing their versions of IComparable/IComparator and collections of their own if they have a need to sort or search using custom classes.

Diddy's ArrayList utilises both an IComparable interface and an AbstractComparator class. Use the interface when it's your own class, and a comparator if it's a system type. ArrayList has a default comparator that sorts all the primitives (including String).