On Saturday, 12 November 2016 at 19:13:13 UTC, Nordlöw wrote:
I'm looking for libraries/snippets (either in D or similar
languages) that perform variable-length encoding of unsigned
integers onto a bit-stream. Requirement is that smaller inputs
(integer values) should be encoded with equal or fewer bits.
This
0 => [0]
1 => [1,0]
2 => [1,1,0]
is easy but assumes a too extreme input value distribution.
Does anybody have a suggestion for an encoder that is more
suitable for real-world values that are, for instance, normally
distributed?
If you have a sample of your data, perhaps Huffman codes
(https://en.wikipedia.org/wiki/Huffman_coding) might be an option?