Skip to content

Commit

Permalink
Named Digraphs: Implement ListNamedDigraphs as search function
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcontileslie committed Feb 24, 2021
1 parent b6cea6c commit ed0249b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gap/examples.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ DeclareOperation("PetersenGraph", [IsFunction]);
DeclareConstructor("GeneralisedPetersenGraphCons", [IsDigraph, IsInt, IsInt]);
DeclareOperation("GeneralisedPetersenGraph", [IsInt, IsInt]);
DeclareOperation("GeneralisedPetersenGraph", [IsFunction, IsInt, IsInt]);

DeclareOperation("ListNamedDigraphs", [IsString]);
28 changes: 28 additions & 0 deletions gap/examples.gi
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,31 @@ GeneralisedPetersenGraphCons);

InstallMethod(GeneralisedPetersenGraph, "for integer, integer", [IsInt, IsInt],
{n, k} -> GeneralisedPetersenGraphCons(IsImmutableDigraph, n, k));

InstallMethod(ListNamedDigraphs, "for a partially completed string",
[IsString],
function(s)
local l, cands, out, c;
# standardise request
s := LowercaseString(s);
RemoveCharacters(s, " \n\t\r");
l := Length(s);

# load database if not already done
DIGRAPHS_LoadNamedGraph6Strings();

# retrieve candidates
cands := RecNames(DIGRAPHS_NamedGraph6String);
if l = 0 then
return cands;
fi;

# add to out-list all valid completions of the request s
out := [];
for c in cands do
if c{[1..l]} = s then
Add(out, c);
fi;
od;
return out;
end);

0 comments on commit ed0249b

Please sign in to comment.