z = merge(x, y, f)
Key-value pairs whose keys appear in only one of the input tables appear unchanged in the output table. If the key k appears in both x and y, then f(x#k, y#k) is the value associated to k in the output hash table.
For example, we could take the max of the two values, their average, or make a list containing both.
|
|
|
|
|
If the function f(x#k, y#k) returns continue, then the key k is omitted from the merged table.
|
Here is a simple implementation of the free abelian group on four letters, where each element is represented as a hash table that associates coefficients to strings.
|
|
|
|
|
If x and y have the same class and have the same parent, as in the previous example, then so will z.
|
|
|
The function combine allows much greater control when combining two hash tables: you can give functions for how to handle every key and value of the input tables, not just the duplicates. The function mergePairs is similar to merge, but works on lists of pairs rather than hash tables.
The object merge is a compiled function.
The source of this document is in Macaulay2Doc/functions/merge-doc.m2:111:0.