From: Jean Privat Date: Fri, 30 Jan 2015 09:36:28 +0000 (+0700) Subject: Since keys of Maps can now be null, it enables the same rule with the Sets X-Git-Tag: v0.7.2~38^2 X-Git-Url: http://nitlanguage.org?ds=sidebyside Since keys of Maps can now be null, it enables the same rule with the Sets Signed-off-by: Jean Privat --- diff --git a/lib/counter.nit b/lib/counter.nit index 3d1555b..6545b73 100644 --- a/lib/counter.nit +++ b/lib/counter.nit @@ -35,7 +35,7 @@ import poset # 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 @@ -181,7 +181,8 @@ class Counter[E: Object] 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 @@ -201,7 +202,8 @@ class Counter[E: Object] 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 @@ -238,7 +240,7 @@ class Counter[E: Object] end end -private class CounterComparator[E: Object] +private class CounterComparator[E] super Comparator redef type COMPARED: E var counter: Counter[E] diff --git a/lib/poset.nit b/lib/poset.nit index a5425dd..568f968 100644 --- a/lib/poset.nit +++ b/lib/poset.nit @@ -71,7 +71,7 @@ module poset # # 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 @@ -379,7 +379,7 @@ end # # ... # t.in_some_relation.greaters # ~~~ -class POSetElement[E: Object] +class POSetElement[E] # The poset self belong to var poset: POSet[E] diff --git a/lib/standard/collection/abstract_collection.nit b/lib/standard/collection/abstract_collection.nit index bb17064..858d569 100644 --- a/lib/standard/collection/abstract_collection.nit +++ b/lib/standard/collection/abstract_collection.nit @@ -305,7 +305,7 @@ end # # ... # s.add(a) # assert s.has(b) == true -interface Set[E: Object] +interface Set[E] super SimpleCollection[E] redef fun has_only(item) diff --git a/lib/standard/collection/array.nit b/lib/standard/collection/array.nit index 44ea5d3..ae351cf 100644 --- a/lib/standard/collection/array.nit +++ b/lib/standard/collection/array.nit @@ -471,7 +471,7 @@ end # Others collections ########################################################## # A set implemented with an Array. -class ArraySet[E: Object] +class ArraySet[E] super Set[E] # The stored elements. @@ -522,7 +522,7 @@ class ArraySet[E: Object] 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 diff --git a/lib/standard/collection/hash_collection.nit b/lib/standard/collection/hash_collection.nit index f3857293..f4f218e 100644 --- a/lib/standard/collection/hash_collection.nit +++ b/lib/standard/collection/hash_collection.nit @@ -408,7 +408,7 @@ end # 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] @@ -462,12 +462,12 @@ class HashSet[E: Object] 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 diff --git a/lib/standard/collection/union_find.nit b/lib/standard/collection/union_find.nit index f9ac76f..4df80b5 100644 --- a/lib/standard/collection/union_find.nit +++ b/lib/standard/collection/union_find.nit @@ -31,7 +31,7 @@ import hash_collection # 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