private void Write31Bits(List<uint> list, int index, uint val)
{
ResizeAsNeeded(list, index + 32);
int off = (index%32);
int pointer = index >> 5;
if (pointer >= list.Count - 1)
list.Add(0);
ulong l = ((ulong) list[pointer] << 32) + list[pointer + 1];
l |= (ulong) val << (33 - off);
list[pointer] = (uint) (l >> 32);
list[pointer + 1] = (uint) (l & 0xffffffff);
}