A Survey on Learning to Hash