chickadee » slib-wt-tree » wt-tree/union-merge

wt-tree/union-merge tree1 tree2 combineprocedure

combine is a procedure of three arguments returning a single value.

Returns a new tree containing all the associations from both tree1 and tree2. When both trees have an association for the same key, combine is applied to the key and to both associated values, in that order, and the result is associated with the key.

Assuming that combine runs in O(1) time, the worst-case time required by this operation is proportional to the sum of the sizes of both trees. If the minimum key of one tree is greater than the maximum key of the other tree then the time required is at worst proportional to the logarithm of the size of the larger tree.

Example:

(let ((t1 (singleton-wt-tree number-wt-type 4 8))
      (t2 (singleton-wt-tree number-wt-type 4 71)))
  (wt-tree/lookup
   (wt-tree/union-merge t1
                        t2
                        (lambda (_key v1 v2)
                          (+ v1 v2)))
   4
   #f))
; -> 79