Generalize pair hash function