Have encode take a list as input

By using a list instead of a vector we can encode in constant space.
Fixes #42.