Add support for sparse entries.

This also should also improve the memory efficiency, but I didn't bother getting numbers on that, I needed it for the functionality anyway, it's just a happy coincidence. :smiley: 
Add a comment that this must be called with `lock_` locked.
(and wistfully dream of threading annotations etc. etc.)