Skip to content

Commit

Permalink
Add support for sequence arguments to hashTable
Browse files Browse the repository at this point in the history
  • Loading branch information
d-torrance committed Dec 28, 2024
1 parent c9579e8 commit 12a88ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 9 additions & 9 deletions M2/Macaulay2/d/hashtables.dd
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ toHashTable(e:Expr):Expr := (
when e
is w:List do toHashTable(w.v)
is s:Sequence do (
if length(s) != 2 then return WrongNumArgs(1,2);
when s.0
is FunctionClosure do nothing
is CompiledFunction do nothing
is CompiledFunctionClosure do nothing
else return WrongArg(1,"a function");
when s.1 is w:List do toHashTableWithCollisionHandler(w.v,s.0)
else WrongArg(2,"a list"))
else WrongArg("a list"));
if length(s) == 2 then (
if isFunction(s.0) then (
when s.1
is w:Sequence do toHashTableWithCollisionHandler(w, s.0)
is w:List do toHashTableWithCollisionHandler(w.v, s.0)
else WrongArg(2, "a list or sequence"))
else toHashTable(s))
else toHashTable(s))
else WrongArg("a list or sequence"));
setupfun("hashTable",toHashTable);

copy(table:array(KeyValuePair)):array(KeyValuePair) := (
Expand Down
2 changes: 2 additions & 0 deletions M2/Macaulay2/tests/normal/hashtables.m2
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ x = set(1..10)
assert(select(x, odd) === set {1, 3, 5, 7, 9})
assert(select(2, x, odd) == set {1, 3})

assert(hashTable ((0, 1), (1, 2)) === hashTable {(0, 1), (1, 2)})

-- Local Variables:
-- compile-command: "make -C $M2BUILDDIR/Macaulay2/packages/Macaulay2Doc/test hashtables.out"
-- End:

0 comments on commit 12a88ba

Please sign in to comment.