- iterator end on reverse-iterable data structures

This commit is contained in:
Emir Pasic
2016-06-27 00:41:32 +02:00
parent 57162feff5
commit f052c96069
9 changed files with 118 additions and 16 deletions
+7 -1
View File
@@ -149,6 +149,12 @@ func (iterator *Iterator) Begin() {
iterator.index = -1
}
// End moves the iterator past the last element (one-past-the-end).
// Call Prev() to fetch the last element if any.
func (iterator *Iterator) End() {
iterator.index = iterator.stack.Size()
}
// First moves the iterator to the first element and returns true if there was a first element in the container.
// If First() returns true, then first element's index and value can be retrieved by Index() and Value().
// Modifies the state of the iterator.
@@ -161,7 +167,7 @@ func (iterator *Iterator) First() bool {
// If Last() returns true, then last element's index and value can be retrieved by Index() and Value().
// Modifies the state of the iterator.
func (iterator *Iterator) Last() bool {
iterator.index = iterator.stack.Size()
iterator.End()
return iterator.Prev()
}