Speaking of wow, we’ve covered so much in this chapter! We looked at sets, Boolean arrays, and bit vectors. We also looked at binary numbers, bitwise operators, and various bit manipulation techniques. We discovered how Boolean arrays can produce unique speed boosts, and how bit vectors can offer astounding space savings.
Although we implemented bit vectors from scratch, it’s worth noting that there’s also a popular Python bit vector library out there called bitarray. You should definitely check that out if you’re planning on using bit vectors in production.
There does appear to be a significant limitation to Boolean arrays and bit vectors. That is, they can only be used in scenarios where the possible set values are integers and these integers lie in a relatively small range. If, for example, our set values are strings, these data structures won’t be very useful. Or so it would seem.
In the next chapter, we’ll look at how we can harness the power of bit vectors for all types of values, strings included. With a little help from Monte Carlo algorithms, we can create a bit-vector-like data structure that works in many other scenarios beyond a small range of integers. Prepare to be amazed.