Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Pascal strings can be improved to support strings of any reasonable length.

Say two highest bits of the counter set the size of the counter field. 00 = 6 remaining bits, 01 = 14 bits (2 bytes), 10 = 30 bits, 11 = 62 bits (8 bytes).

A simple `counter* & 0x3f` would remove the width-setting bits, without any shifts, additions, etc.

This allows small strings to use only 1 byte for the counter, while allowing huge strings that span the entire RAM.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: