Skip to content

Commit

Permalink
Simplify and unify GAP iteration code (#3302)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored Feb 1, 2024
1 parent 45d7d5c commit 070219e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
14 changes: 3 additions & 11 deletions src/Groups/GAPGroups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,10 @@ comm(x::GAPGroupElem, y::GAPGroupElem) = x^-1*x^y
Base.IteratorSize(::Type{<:GAPGroup}) = Base.SizeUnknown()
Base.IteratorSize(::Type{PermGroup}) = Base.HasLength()

function Base.iterate(G::GAPGroup)
L = GAPWrap.Iterator(G.X)::GapObj
i = GAPWrap.NextIterator(L)::GapObj
return group_element(G, i), L
end
Base.iterate(G::GAPGroup) = iterate(G, GAPWrap.Iterator(G.X))

function Base.iterate(G::GAPGroup, state)
if GAPWrap.IsDoneIterator(state)
return nothing
end
GAPWrap.IsDoneIterator(state) && return nothing
i = GAPWrap.NextIterator(state)::GapObj
return group_element(G, i), state
end
Expand Down Expand Up @@ -680,9 +674,7 @@ Base.IteratorSize(::Type{<:GAPGroupConjClass}) = Base.SizeUnknown()
Base.iterate(cc::GAPGroupConjClass) = iterate(cc, GAPWrap.Iterator(cc.CC))

function Base.iterate(cc::GAPGroupConjClass{S,T}, state::GapObj) where {S,T}
if GAPWrap.IsDoneIterator(state)
return nothing
end
GAPWrap.IsDoneIterator(state) && return nothing
i = GAPWrap.NextIterator(state)::GapObj
if T <: GAPGroupElem
return group_element(cc.X, i), state
Expand Down
8 changes: 2 additions & 6 deletions src/Groups/cosets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,7 @@ Base.IteratorSize(::Type{<:GroupCoset}) = Base.SizeUnknown()
Base.iterate(G::GroupCoset) = iterate(G, GAPWrap.Iterator(G.X))

function Base.iterate(G::GroupCoset, state)
if GAPWrap.IsDoneIterator(state)
return nothing
end
GAPWrap.IsDoneIterator(state) && return nothing
i = GAPWrap.NextIterator(state)::GapObj
return group_element(G.G, i), state
end
Expand Down Expand Up @@ -614,9 +612,7 @@ Base.IteratorSize(::Type{<:GroupDoubleCoset}) = Base.SizeUnknown()
Base.iterate(G::GroupDoubleCoset) = iterate(G, GAPWrap.Iterator(G.X))

function Base.iterate(G::GroupDoubleCoset, state)
if GAPWrap.IsDoneIterator(state)
return nothing
end
GAPWrap.IsDoneIterator(state) && return nothing
i = GAPWrap.NextIterator(state)::GapObj
return group_element(G.G, i), state
end
Expand Down
11 changes: 2 additions & 9 deletions src/Groups/matrices/MatGrp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,10 @@ end

Base.IteratorSize(::Type{<:MatrixGroup}) = Base.SizeUnknown()

function Base.iterate(G::MatrixGroup)
L=GAPWrap.Iterator(G.X)::GapObj
@assert ! GAPWrap.IsDoneIterator(L)
i = GAPWrap.NextIterator(L)::GapObj
return MatrixGroupElem(G, i), L
end
Base.iterate(G::MatrixGroup) = iterate(G, GAPWrap.Iterator(G.X))

function Base.iterate(G::MatrixGroup, state::GapObj)
if GAPWrap.IsDoneIterator(state)
return nothing
end
GAPWrap.IsDoneIterator(state) && return nothing
i = GAPWrap.NextIterator(state)::GapObj
return MatrixGroupElem(G, i), state
end
Expand Down

0 comments on commit 070219e

Please sign in to comment.