Count-Min Sketch (2019)
florian.github.io
florian.github.io
The code is also open source, and I've improved on it a bit: https://github.com/lmb/socklimit Not production ready but a cool idea and implementation.
I saw in your socklimit project looks like `fasthash64` and `hashlittle` I'm not familiar with those any insight or recommended reading to understand these hash functions?
p.s. googling pairwise independent hash functions did get me some college class reading but doesn't mention any named hash functions developed out in the world.
Pairwise independence basically means that applying 2 different hash functions to the same key produces 2 distinct/seemingly random values. There's a much more precise mathematical definition but that's the essence.
I would probably choose different, more robust hash functions if I was targeting regular C.
I really would love to see a book that basically just covers all the cool data structures people have come up with using hash functions.
1. pick a substring length L to look for
2. pick a number M for how many "most common substrings
of length L" we wish to find
3. initiate a count-min sketch for approximate counting
of substrings, and an array of size M for keeping
track of the top M substrings
4. do a linear scan over the input (length N) to count
each substring of length L (so ideally we'd be using
rolling hashes for the count-min sketch)
We probably would have some false positives, and partialy overlapping substrings (I expect the latter is a difficult problem to solve elegantly, unless scanning over the text in steps of L works better than I think it would), but it might be an efficient heuristic.The exhaustive search would be almost the same but use a prefix tree (aka trie) instead of a CMS, which has good average case overhead because tree, but if we're dealing with a "every substring is as unique as possible" worst case scenarios memory overhead could blow up to [input size times fairly big constant].
Said worst case scenario is quite easy to construct btw, just start with https://oeis.org/A142150 using 8 bit numbers, then modify to exhaust all remaining three-number combinations after exhausting all unique pair combinations, and so on.