Dictionary Compression
kevincox.ca
kevincox.ca
Why? The site is static, so it's cached and browsers get a 304 when they come back. For new players the server compresses the whole thing in flight, not just the word list.
Doing some fancy domain-specific compression on the word list would have added unnecessary complexity (read: places for bugs to creep in) and taken time/effort away from more important things.
> The speed-up is significant, about 20x faster. This makes sense because instead of scanning half of all words on average, you only need to scan half of the words with the same first letter. I’ll assume this isn’t exactly 13x due to letter distribution.
Extremely minor, but I think one would still expect a 26x speedup, right? You go from searching half of all words to half of 1/26th of all words. Obviously there are more words starting with S than X and all, but my question is just in theory.
Put differently, is there any way to leverage scenarios where you have a practically-unlimited dictionary size and willingness to retain all data forever? Or, am I playing with some basic information theory equation the wrong way in my mind?
I did consider perfect hashing, however IIUC it will map a fixed set of entries to sequential integers, but it won't do something clever for items not in the set, so I couldn't find a way to make it work well for this problem. I did see someone talking about perfect bloom filters but to be honest I didn't quite understand it https://iswsa.acm.org/bloom.html
https://gist.github.com/cfreshman/a03ef2cba789d8cf00c08f767e...
Here is the code:
X = fread(fid, sprintf('*ubit%d', nBits));
M = numel(X);
words = double(unique(X))';
binEdges = [words-0.5; words+0.5];
binEdges = unique(binEdges(:));
P = histcounts(X, binEdges) / M;
P(P == 0) = [];
H = -sum(P .* log(P) ./ log(max([nBits, 2]))) / nBits * log2(max([nBits, 2]));
E = H * M * nBits;
This is a textbook entropy implementation and I've been under the impression that you'll never do better than this (for a given word size).