[Haskell-cafe] two problems with Data.Binary and Data.ByteString

Tim Newsham newsham at lava.net
Tue Aug 12 20:58:38 EDT 2008


> Maybe it makes sense to have the streamble list instance in Binary as
> well, with some examples?

A flexible format that doesn't sacrifice too much space efficiency
would be to encode in chunks of up to 255 elements:

  Chunk = {
     length :: Word8
     elems :: [Elem]  --  0..255 repetitions
   }
  Chunks = [Chunk] -- terminated with the first 0 length Chunk

streamable, amortized cost is about 1/256th of the length, and
the encoding is much more efficient than the current scheme
for short lists (like most strings).  Currently a string "foobar"
is 8 bytes for length and 7 for the actual string.

> -- Don

Tim Newsham
http://www.thenewsh.com/~newsham/


More information about the Haskell-Cafe mailing list