Format

values_dot(A, B)

Returns

The dot product of all associated numbers in A and B

Args

A, B: An associative list or alist

Returns the dot product of two associative lists. If the same item exists in both lists, the associated values are multiplied together as numbers. All of those multiplications are added together to form the dot product. This is similar to vector dot products.

var/list/first = list("a"=1, "b"=2, "c"=3)
var/list/second = list("b"=4, "c"=5, "d"=6)
// first["a"] * second["a"] = 1 * 0 = 0
// first["b"] * second["b"] = 2 * 4 = 8
// first["c"] * second["c"] = 3 * 5 = 15
// first["d"] * second["d"] = 0 * 6 = 0
// total is 23
usr << values_dot(first, second)  // outputs 23

This is a convenience proc for games trying to eke out high performance.

See also