# assert c.max == "b" # because "b" has the most count (3)
# assert c.avg == 2.0 # because it is the mean of the counts
# ~~~~
-class Counter[E: Object]
+class Counter[E]
super Map[E, Int]
# Total number of counted occurrences
fun max: nullable E do
var max: nullable Int = null
var elem: nullable E = null
- for e, v in map do
+ for e in map.keys do
+ var v = map[e]
if max == null or v > max then
max = v
elem = e
fun min: nullable E do
var min: nullable Int = null
var elem: nullable E = null
- for e, v in map do
+ for e in map.keys do
+ var v = map[e]
if min == null or v < min then
min = v
elem = e
end
end
-private class CounterComparator[E: Object]
+private class CounterComparator[E]
super Comparator
redef type COMPARED: E
var counter: Counter[E]