>>47
http://lists.gnu.org/archive/html/guile-devel/2011-03/msg00122.html
The simplest solution is to break the stringbuf into chunks, where each
chunk holds exactly CHUNK_SIZE characters, except for the last chunk
which might have fewer. To find a character at index i, we scan forward
(i % CHUNK_SIZE) characters from the beginning of chunk[i / CHUNK_SIZE].
Ideally, CHUNK_SIZE is a power of 2, which allows us to use bitwise
operations instead of division. The number of characters to scan is
bounded by CHUNK_SIZE, and therefore takes O(1) time.
String-set! in general requires us to resize a chunk. Although chunks
contain a constant number of characters, that of course maps to a
variable number of bytes. There are various tricks we can do to reduce
the number of reallocations done, but even in the worse case, the time
spent is bounded by CHUNK_SIZE, and thus O(1).