private class CircularListIterator[E]
super IndexedIterator[E]
- redef var key: Int
+ redef var index: Int
# The current node pointed.
# Is null if the list is empty.
do
# Empty lists are not OK.
# Pointing again the first node is not OK.
- return self.node != null and (self.key == 0 or self.node != self.list.node)
+ return self.node != null and (self.index == 0 or self.node != self.list.node)
end
redef fun next
do
self.node = self.node.next
- self.key += 1
+ self.index += 1
end
redef fun item do return self.node.item
do
self.node = list.node
self.list = list
- self.key = 0
+ self.index = 0
end
end
# Indexed collection are ordoned collections.
# The first item is 0. The last is `length'-1.
interface SequenceRead[E]
- super MapRead[Int, E]
+ super Collection[E]
# Get the first item.
# Is equivalent with `self'[0].
redef fun first
assert not_empty: not is_empty
return self[0]
end
-
+
+ fun [](index: Int): E is abstract
+
# Get the last item.
# Is equivalent with `self'[`length'-1].
fun last: E
# The first item is 0. The last is `length'-1.
interface Sequence[E]
super SequenceRead[E]
- super Map[Int, E]
super SimpleCollection[E]
# Set the first item.
# Is equivalent with `self'[0] = `item'.
# The second item become the first.
fun shift: E is abstract
+ # Set the`item' at `index'.
+ fun []=(index: Int, item: E) is abstract
+
+ # Remove the item at `index' and shift all following elements
+ fun remove_at(index: Int) is abstract
end
# Iterators on indexed collections.
interface IndexedIterator[E]
- super MapIterator[Int, E]
+ super Iterator[E]
# The index of the current item.
fun index: Int is abstract
-
- # A synonym of index.
- redef fun key do return index
end
# Associatives arrays that internally uses couples to represent each (key, value) pairs.