Skip to content

Commit

Permalink
Add iterator over I/O devices
Browse files Browse the repository at this point in the history
  • Loading branch information
JBlaschke committed Jan 6, 2024
1 parent dcfe3ba commit 3c6e5af
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lowlevel_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,18 @@ IteratorSize(::Type{Object}) = Base.SizeUnknown()
IteratorEltype(::Type{Object}) = Base.HasEltype()
eltype(::Type{Object}) = Object
isempty(::Object) = false
iterate(obj::Object) = (obj, isempty(obj.memory_children) ? obj.children : vcat(obj.memory_children, obj.children))
function iterate(obj::Object)
state = vcat(obj.children, obj.memory_children, obj.io_children)
return obj, state
end
function iterate(::Object, state::Vector{Object})
isempty(state) && return nothing
# depth-first traversal
# obj = shift!(state)
obj, state = state[1], state[2:end]
prepend!(state, obj.children)
prepend!(state, obj.memory_children)
prepend!(state, obj.io_children)
return obj, state
end
# length(obj::Object) = mapreduce(x->1, +, obj)
Expand Down

0 comments on commit 3c6e5af

Please sign in to comment.