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.
This change should maintain backwards compatibility with earlier versions.
See the addition to README.md for some usage examples.