This removes some unsafe code and prepare for a potential strictier nullabe type
implementation.
Signed-off-by: Jean Privat <jean@pryen.org>
# Conflicts:
#
# lib/standard/collection/hash_collection.nit
# ...
# s.add(a)
# s.has(b) # --> true
-interface Set[E]
+interface Set[E: Object]
special SimpleCollection[E]
redef fun has_only(item)
redef fun remove_all(item) do remove(item)
end
-interface MapRead[K, E]
+interface MapRead[K: Object, E]
special Collection[E]
# Get the item at `key'.
fun [](key: K): E is abstract
# map[u2] # -> v2
# map.has_key(u1) # -> true
# map.has_key(u3) # -> false
-interface Map[K, E]
+interface Map[K: Object, E]
special RemovableCollection[E]
special MapRead[K, E]
# Set the`item' at `key'.
end
# Iterators for Map.
-interface MapIterator[K, E]
+interface MapIterator[K: Object, E]
special Iterator[E]
# The key of the current item.
fun key: K is abstract
end
# Associatives arrays that internally uses couples to represent each (key, value) pairs.
-interface CoupleMap[K, E]
+interface CoupleMap[K: Object, E]
special Map[K, E]
# Return the couple of the corresponding key
# Return null if the key is no associated element
# Iterator on CoupleMap
#
# Actually is is a wrapper around an iterator of the internal array of the map.
-class CoupleMapIterator[K, E]
+class CoupleMapIterator[K: Object, E]
special MapIterator[K, E]
redef fun item do return _iter.item.second
# Others collections ##########################################################
# A set implemented with an Array.
-class ArraySet[E]
+class ArraySet[E: Object]
special Set[E]
# The stored elements.
var _array: Array[E]
end
# Iterators on sets implemented with arrays.
-class ArraySetIterator[E]
+class ArraySetIterator[E: Object]
special Iterator[E]
redef fun is_ok do return _iter.is_ok
# Associative arrays implemented with an array of (key, value) pairs.
-class ArrayMap[K, E]
+class ArrayMap[K: Object, E]
special CoupleMap[K, E]
# O(n)
end
end
-private class HashNode[K]
+private class HashNode[K: Object]
var _key: K
type N: HashNode[K]
readable writable var _next_item: nullable N = null
end
end
-class HashMap[K, V]
+class HashMap[K: Object, V]
special Map[K, V]
special HashCollection[K, HashMapNode[K, V], V]
redef fun []=(key, v)
do
- assert key != null
var i = index_at(key)
var c = node_at_idx(i, key)
if c != null then
end
end
-class HashMapNode[K, V]
+class HashMapNode[K: Object, V]
special HashNode[K]
redef type N: HashMapNode[K, V]
var _value: V
end
end
-class HashMapIterator[K, V]
+class HashMapIterator[K: Object, V]
special MapIterator[K, V]
redef fun is_ok do return _node != null
end
end
-class HashSet[E]
+class HashSet[E: Object]
special Set[E]
special HashCollection[E, HashSetNode[E], E]
end
end
-class HashSetNode[E]
+class HashSetNode[E: Object]
special HashNode[E]
redef type N: HashSetNode[E]
end
end
-class HashSetIterator[E]
+class HashSetIterator[E: Object]
special Iterator[E]
redef fun is_ok do return _node != null
# Handles partial ordered sets (ie hierarchies)
# Thez are built by adding new element at the bottom of the hierarchy
-class PartialOrder[E]
+class PartialOrder[E: Object]
special Collection[E]
# Elements
var _elements: Map[E, PartialOrderElement[E]]
end
end
-class PartialOrderElement[E]
+class PartialOrderElement[E: Object]
# The partial order where belong self
readable var _order: PartialOrder[E]