mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Address Ameba issue
This commit is contained in:
parent
94d5c96e7d
commit
38ea2e7f96
1 changed files with 10 additions and 15 deletions
|
@ -18,25 +18,20 @@ module Spectator
|
||||||
# Retrieves the next `Node`.
|
# Retrieves the next `Node`.
|
||||||
# If there are none left, then `Iterator::Stop` is returned.
|
# If there are none left, then `Iterator::Stop` is returned.
|
||||||
def next
|
def next
|
||||||
# Keep going until either:
|
# Nothing left to iterate.
|
||||||
# a. a node is found.
|
return stop if @stack.empty?
|
||||||
# b. the stack is empty.
|
|
||||||
until @stack.empty?
|
|
||||||
# Retrieve the next node.
|
|
||||||
node = @stack.pop
|
|
||||||
|
|
||||||
# If the node is a group, add its direct children to the queue
|
# Retrieve the next node.
|
||||||
# in reverse order so that the tree is traversed in pre-order.
|
node = @stack.pop
|
||||||
if node.is_a?(Indexable(Node))
|
|
||||||
node.reverse_each { |child| @stack.push(child) }
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return the current node.
|
# If the node is a group, add its direct children to the queue
|
||||||
return node
|
# in reverse order so that the tree is traversed in pre-order.
|
||||||
|
if node.is_a?(Indexable(Node))
|
||||||
|
node.reverse_each { |child| @stack.push(child) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Nothing left to iterate.
|
# Return the current node.
|
||||||
stop
|
node
|
||||||
end
|
end
|
||||||
|
|
||||||
# Restart the iterator at the beginning.
|
# Restart the iterator at the beginning.
|
||||||
|
|
Loading…
Reference in a new issue