using hash_table reduce an O(n^2) algorithm to O(n)