Note that intersections using HLLs don't work in general. The error rates become gigantic for sets that have small intersections, or whose cardinality differs greatly.<p>A general solution to cardinality estimations for intersections is to just use HLLs for union operations, and keep a MinHash sketch for each key as well to perform intersections.<p>There is a very good analysis of this technique over at <a href="http://tech.adroll.com/blog/data/2013/07/10/hll-minhash.html" rel="nofollow">http://tech.adroll.com/blog/data/2013/07/10/hll-minhash.html</a>
It would be really great if this was implemented in stream-lib (<a href="https://github.com/addthis/stream-lib" rel="nofollow">https://github.com/addthis/stream-lib</a>), which is a pretty standard library for HLL counters.<p>Also, the community supporting that lib is very familiar with the mathematics behind these structures, and would be be better able to critique the error rates and such.