| You could use a faster sort implementation, such as radix sort which is O(n) and also probably faster in practice when well-implemented. One option is this one [1] which I actually wrote as part of this exact task: de-duplicating a list of integers, as part of working on [2]. I wrote about the types of speedups you can expect with radix sort here [3] - it depends on the size of the input elements and their distribution (e.g., if many top bits are zero, radix sort will be much faster), but in my test case I see a ~5x speedup for moderate or large input sizes (thousands of elements or more). Of course, the same could be said about hash tables... [1] https://github.com/travisdowns/sort-bench/blob/master/radix7... [2] https://lemire.me/blog/2019/05/07/almost-picking-n-distinct-... [3] https://travisdowns.github.io/blog/2019/05/22/sorting.html |