# Get a new iterator on the collection.
fun iterator: Iterator[E] is abstract
- # Iterate over each element of the collection
- fun iterate
- !each(e: E)
- do
- var i = iterator
- while i.is_ok do
- each(i.item)
- i.next
- end
- end
-
# Is there no item in the collection?
#
# assert [1,2,3].is_empty == false
if other.length != length then return false
return has_all(other)
end
+
+ # because of the law between `==` and `hash`, hash is redefined to be the sum of the hash of the elements
+ redef fun hash
+ do
+ var res = 0
+ for e in self do res += res.hash
+ return res
+ end
end
# MapRead are abstract associative collections: `key` -> `item`.
# Get a new iterator on the map.
fun iterator: MapIterator[K, E] is abstract
- # Iterate over each element of the collection
- fun iterate
- !each(k: K, v: E)
- do
- var i = iterator
- while i.is_ok do
- each(i.key, i.item)
- i.next
- end
- end
-
# Return the point of view of self on the values only.
# Note that `self` and `values` are views on the same data;
# therefore any modification of one is visible on the other.
end
redef fun iterator: IndexedIterator[E] is abstract
+
+ # Two sequences are equals if they have the same items in the same order.
+ redef fun ==(o)
+ do
+ if not o isa SequenceRead[nullable Object] or o is null then return false
+ var l = length
+ if o.length != l then return false
+ var i = 0
+ while i < l do
+ if self[i] != o[i] then return false
+ i += 1
+ end
+ return true
+ end
+
+ # because of the law between `==` and `hash`, hash is redefined to be the sum of the hash of the elements
+ redef fun hash
+ do
+ var res = 0
+ for e in self do res += res.hash
+ return res
+ end
end
# Sequence are indexed collection.