Skip to content

Commit

Permalink
Further simplify dedupSymbols
Browse files Browse the repository at this point in the history
Remove unused "mapping" hash table and call "repeats" once per
iteration of the while loop.
  • Loading branch information
d-torrance authored and mgacummings committed Oct 18, 2024
1 parent 8e4323d commit 40361bc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions M2/Macaulay2/m2/monoids.m2
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,12 @@ checkSymbol = sym -> if instance(sym, Symbol) or lookup(symbol <-, class sym) =!
-- turns {x, y, z, y} into {x, y_0, z, y_1}
-- adding 'toString' in a few places will eliminate more duplications
-- but makes creating temporary rings in functions more difficult.
dedupSymbols = varlist -> if 0 == repeats varlist then varlist else while 0 < repeats varlist do (
mapping := hashTable toList pairs varlist;
counter := applyPairs(tally varlist, (name, count) ->
name => new MutableList from if count == 1 then {name} else makeVars(count, name));
varlist = apply(varlist, var -> remove(counter#var, 0));
if 0 == repeats varlist then break varlist else varlist)
dedupSymbols = varlist -> (
while 0 < repeats varlist do (
counter := applyPairs(tally varlist, (name, count) ->
name => new MutableList from if count == 1 then {name} else makeVars(count, name));
varlist = apply(varlist, var -> remove(counter#var, 0)));
varlist)

-- also used in AssociativeAlgebras.m2
findSymbols = varlist -> dedupSymbols toList apply(pairs listSplice varlist,
Expand Down

0 comments on commit 40361bc

Please sign in to comment.