Boolean Arrays
We’ve looked at a couple of examples where sets offer considerable speed benefits. In particular, we took full advantage of a hash table’s O(1) lookups to achieve some really fast code.
The interesting thing, though, is that there’s an even faster set data structure than a hash table. Don’t get me wrong; hash tables are great for serving as sets. But in certain scenarios, other data structures can be even faster. One such data structure is the Boolean array. The name may sound fancy, but it’s simply a regular array in which we only store the values True or False. The array [True, True, False, True, False, False, True] is a Boolean array.
A Boolean array can serve as a set when our data consists of integers that lie in a relatively ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access