LinkedImmutableString is designed for storing rows (values) in hash join.
It does not need a length, since it is implicit from the contents; however, since there might be multiple values with the same key, we simulate a multimap by having a “next” pointer. (Normally, linked lists are a bad idea due to pointer chasing, but here, we're doing so much work for each value that the overhead disappears into the noise.)
As the next pointer is usually be very close in memory to ourselves (nearly all rows are stored in the same MEM_ROOT), we don't need to store the entire pointer; instead, we store the difference between the start of this string and the next pointer, as a zigzag-encoded Varint128. As with the length in ImmutableStringWithLength, this typically saves 6–7 bytes for each value. The special value of 0 means that there is no next pointer (ie., it is nullptr), as that would otherwise be an infinite loop.
Encode the given string and “next” pointer as a header for LinkedImmutableString, and returns a new object pointing to it.
Note that unlike ImmutableStringWithLength::Encode(), this only encodes the header; since there is no explicitly stored length, you must write the contents of the string yourself.
*dst must contain at least the number of bytes returned by RequiredBytesForEncode. It is moved to one byte past the end of the written stream (which is the right place to store the string itself).