combine

combine(x,y,f,g,h) -- yields the result of combining hash tables x and y, using f to combine keys, g for values, and h for collisions.

The objects are assumed to have the same class, and the result will have the class of one of them. The combined object will contain f(p,q) => g(b,c) when x contains p => b and y contains q => c. The function h is used to combine values when key collisions occur in the result, as with merge. The function h should be a function of two arguments; it may assume that its first argument will be the value accumulated so far, and its second argument will be the result g(b,c) from a single pair of values. Normally h will be an associative and commutative function.

The result is mutable if and only if x or y is.

This function can be used for multiplying polynomials, where it will be used in code like this.

          combine(x, y, monomialTimes, coeffTimes, coeffPlus)

topindexpreviousupnext