TLDR · PROGRAMMING, DESIGN & DATA SCIENCE

HASHED SORTING IS TYPICALLY FASTER THAN HASH TABLES

reiner.org18 min read

Summary from the TLDR newsletter

The two standard approaches for counting the unique values in a large array of mostly-unique uint64s are to insert into a hash table and return the number of entries, or to sort the array, then count positions that differ from their predecessor. Sorting is typically faster than hash tables in a well-tuned implementation. This problem and its variants are the inner loop of some of the world's biggest CPU workloads. This article takes a look at why sorting wins, when one should choose hash tables versus a sort, and why it matters.