2 ms·
Interesting idea. It makes me think of the indirect blocks used in Unix style file systems. But I'm unclear on some points. Should the 253 in the second case (s
by rootbear 11y ago
Interesting idea. It makes me think of the indirect blocks used in Unix style file systems. But I'm unclear on some points. Should the 253 in the second case (s[0] == 254) be 255? It's not clear why it ends at 253. Second, how is the end of the string found in the cases two and three? I'm assuming the last part of the chain would be a string segment of type 1, with the length of the final segment given in the first byte.
- makecheck 11y agoActually in cases 2 and 3, since the first byte is "special", the length of the actual string must be the next byte. I've updated it to show that. This is why there is no length-254 string. And in the 3rd case, the maximum segment length is 10 bytes shorter. For a multi-segment setup the length of the entire string would be found by summing the lengths of each segment. This is still "fast" because you would have to, at most, test one byte per segment to find the next length byte, to find the total string length.