There's a pretty significant memory savings for the sorted version. Instead of keeping map of hash to true, you keep only the last value you saw.