Add the ability to use custom key and weight selection functions.

This commit adds the ability to use custom key and weight selectors, allowing users to use more complex data structures without any (potentially costly) preprocessing.
See the addition to README.md for some usage examples.