Skip to content

Commit

Permalink
oper: reinstate 3-arg DigraphAddVertices
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfwilson committed Oct 5, 2019
1 parent e47d72e commit 82bd4dd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/oper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ true
Label="for a digraph and an integer"/>
<Oper Name="DigraphAddVertices" Arg="digraph, labels"
Label="for a digraph and a list of labels"/>
<!-- The 3-argument version is deliberately undocumented. It is redundant,
but it is included for backwards compatibility. -->
<Returns>A digraph.</Returns>
<Description>
For a non-negative integer <A>m</A>, this operation returns a digraph
Expand Down
2 changes: 2 additions & 0 deletions gap/oper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ DeclareOperation("DigraphAddVertex", [IsDigraph]);
DeclareOperation("DigraphAddVertex", [IsDigraph, IsObject]);
DeclareOperation("DigraphAddVertices", [IsDigraph, IsInt]);
DeclareOperation("DigraphAddVertices", [IsDigraph, IsList]);
# 3-arg version of DigraphAddVertices is included for backwards compatibility.
DeclareOperation("DigraphAddVertices", [IsDigraph, IsInt, IsList]);

DeclareOperation("DigraphRemoveVertex", [IsDigraph, IsPosInt]);
DeclareOperation("DigraphRemoveVertices", [IsDigraph, IsList]);
Expand Down
13 changes: 13 additions & 0 deletions gap/oper.gi
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ InstallMethod(DigraphAddVertices, "for an immutable digraph and an integer",
[IsImmutableDigraph, IsInt],
{D, m} -> MakeImmutable(DigraphAddVertices(DigraphMutableCopy(D), m)));

# Included for backwards compatibility, even though the 2nd arg is redundant.
# See https://github.com/gap-packages/Digraphs/issues/264
# This is deliberately kept undocumented.
InstallMethod(DigraphAddVertices, "for a digraph, an integer, and a list",
[IsDigraph, IsInt, IsList],
function(D, m, labels)
if m <> Length(labels) then
ErrorNoReturn("the list <labels> (3rd argument) must have length <m> ",
"(2nd argument),");
fi;
return DigraphAddVertices(D, labels);
end);

InstallMethod(DigraphRemoveVertex,
"for a mutable digraph by out-neighbours and positive integer",
[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt],
Expand Down
12 changes: 12 additions & 0 deletions tst/standard/oper.tst
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,18 @@ false
gap> gr2 = gr3;
true
# DigraphAddVertices (redundant three-argument version)
gap> D := Digraph([[1]]);
<immutable digraph with 1 vertex, 1 edge>
gap> DigraphVertexLabels(D);
[ 1 ]
gap> DigraphAddVertices(D, 2, [fail]);
Error, the list <labels> (3rd argument) must have length <m> (2nd argument),
gap> D := DigraphAddVertices(D, 2, [fail, true]);
<immutable digraph with 3 vertices, 1 edge>
gap> DigraphVertexLabels(D);
[ 1, fail, true ]
# DigraphAddVertex
gap> gr := CompleteDigraph(1);
<immutable empty digraph with 1 vertex>
Expand Down

0 comments on commit 82bd4dd

Please sign in to comment.