refine the algorithm for match function, hash-like function introduced to
reduce the compare times.