import io


def make_string_table(strings):
    """Combine many strings into a single bytestring.

    Arguments:
      strings: List of strings

    Returns:
      (data, strmap), where data is a bytestring containing all of the string
      data, and strmap maps the input strings to their offsets in the
      bytestring. An empty string is always present at offset 0.
    """
    strset = set()
    strlist = []
    for s in sorted(strings, key=lambda s: len(s), reverse=True):
        if s not in strset:
            strlist.append(s)
            strset.update(s[n:] for n in range(len(s)))
    strlist.sort()
    result = io.BytesIO()
    result.write(b"\0")
    for s in strlist:
        result.write(s.encode("ASCII"))
        result.write(b"\0")
    data = result.getvalue()
    strmap = {s: data.index(s.encode("ASCII") + b"\0") for s in strings}
    return data, strmap