Refactor distance calculation (fixes #15, #16, #17)

search_(k)nn now accept custom distance functions (#16) and
return (node, distance) tuples (#15)