Add support for user-supplied key construction function.

Reviewer: @jnealtowns