diff --git a/gap/attr.gi b/gap/attr.gi index e51ea129b..09577b9f7 100644 --- a/gap/attr.gi +++ b/gap/attr.gi @@ -1787,30 +1787,24 @@ function(D) return D; end); -InstallMethod(DigraphAddAllLoops, "for a digraph by out-neighbours", -[IsDigraphByOutNeighboursRep], +InstallMethod(DigraphAddAllLoops, "for a digraph", [IsDigraph], function(D) - local ismulti, C, list, v; - if HasIsReflexiveDigraph(D) and IsReflexiveDigraph(D) then - return D; - fi; - ismulti := IsMultiDigraph(D); + local C, v; C := DigraphMutableCopyIfImmutable(D); - list := C!.OutNeighbours; - Assert(1, IsMutable(list)); - for v in DigraphVertices(C) do - if not v in list[v] then - Add(list[v], v); - if not ismulti then - SetDigraphEdgeLabel(C, v, v, 1); + + if not (HasIsReflexiveDigraph(D) and IsReflexiveDigraph(D)) then + for v in DigraphVertices(C) do + if not IsDigraphEdge(D, v, v) then + DigraphAddEdge(C, v, v); fi; - fi; - od; + od; + fi; + if IsImmutableDigraph(D) then MakeImmutable(C); SetDigraphAddAllLoopsAttr(D, C); SetIsReflexiveDigraph(C, true); - SetIsMultiDigraph(C, ismulti); + SetIsMultiDigraph(C, IsMultiDigraph(D)); SetDigraphHasLoops(C, DigraphNrVertices(C) > 0); fi; return C; diff --git a/tst/standard/attr.tst b/tst/standard/attr.tst index 1dc47d0b5..8571a9e3d 100644 --- a/tst/standard/attr.tst +++ b/tst/standard/attr.tst @@ -2741,7 +2741,7 @@ gap> D := Digraph(IsImmutableDigraph, gap> IsReflexiveDigraph(D); true gap> IsIdenticalObj(D, DigraphAddAllLoops(D)); -true +false # DigraphAddAllLoops - mutable gap> D := Digraph(IsMutableDigraph,