Tmap count values?

BlitzMax Forums/BlitzMax Module Tweaks/Tmap count values?

slenkar(Posted 2008) [#1]
could a function be added to count the number of values in a map?


Brucey(Posted 2008) [#2]
That would be kind of useful, actually.
Although it is not too difficult to subclass the TMap and add the desired functionality yourself.

Something vaguely along the lines of :

type mymap extends tmap

  field size:int

	Method Clear()
		Super.Clear()
		size = 0
	End Method

	Method Insert( key:Object,value:Object )
		if not Contains(key) size:+ 1
		Super.Insert(key, value)
	End Method

	Method Remove( key:Object )
		Super.Remove(key)
		size:- 1
	End Method

        Method Count:Int()
             return size
        End Method
end type


... more or less.


ziggy(Posted 2008) [#3]
Remember to put super.remove(key) in the remove method also.


Brucey(Posted 2008) [#4]
Thanks ziggy !
That's what comes from writing code in the browser ;-)