# 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]
#
# Thanks to the `[]` method, elements can be considered relatively to the poset.
# SEE `POSetElement`
-class POSet[E: Object]
+class POSet[E]
super Collection[E]
super Comparator
# # ...
# t.in_some_relation.greaters
# ~~~
-class POSetElement[E: Object]
+class POSetElement[E]
# The poset self belong to
var poset: POSet[E]
# # ...
# s.add(a)
# assert s.has(b) == true
-interface Set[E: Object]
+interface Set[E]
super SimpleCollection[E]
redef fun has_only(item)
# Others collections ##########################################################
# A set implemented with an Array.
-class ArraySet[E: Object]
+class ArraySet[E]
super Set[E]
# The stored elements.
end
# Iterators on sets implemented with arrays.
-private class ArraySetIterator[E: Object]
+private class ArraySetIterator[E]
super Iterator[E]
redef fun is_ok do return _iter.is_ok
# A `Set` implemented with a hash table.
# Keys of such a map cannot be null and require a working `hash` method
-class HashSet[E: Object]
+class HashSet[E]
super Set[E]
super HashCollection[E]
redef fun new_set do return new HashSet[E]
end
-private class HashSetNode[E: Object]
+private class HashSetNode[E]
super HashNode[E]
redef type N: HashSetNode[E]
end
-private class HashSetIterator[E: Object]
+private class HashSetIterator[E]
super Iterator[E]
redef fun is_ok do return _node != null
# Unkike theorical Disjoint-set data structures, the underling implementation is opaque
# that makes the traditionnal `find` method unavailable for clients.
# The methods `in_same_subset`, `to_partitions`, and their variations are offered instead.
-class DisjointSet[E: Object]
+class DisjointSet[E]
super SimpleCollection[E]
# The node in the hiearchical structure for each element