Pre Hashing Template for O(logn) Comparisons