| 54 | } |
| 55 | |
| 56 | size_t MaxCompressedLength(size_t source_len) { |
| 57 | // Compressed data can be defined as: |
| 58 | // compressed := item* literal* |
| 59 | // item := literal* copy |
| 60 | // |
| 61 | // The trailing literal sequence has a space blowup of at most 62/60 |
| 62 | // since a literal of length 60 needs one tag byte + one extra byte |
| 63 | // for length information. |
| 64 | // |
| 65 | // Item blowup is trickier to measure. Suppose the "copy" op copies |
| 66 | // 4 bytes of data. Because of a special check in the encoding code, |
| 67 | // we produce a 4-byte copy only if the offset is < 65536. Therefore |
| 68 | // the copy op takes 3 bytes to encode, and this type of item leads |
| 69 | // to at most the 62/60 blowup for representing literals. |
| 70 | // |
| 71 | // Suppose the "copy" op copies 5 bytes of data. If the offset is big |
| 72 | // enough, it will take 5 bytes to encode the copy op. Therefore the |
| 73 | // worst case here is a one-byte literal followed by a five-byte copy. |
| 74 | // I.e., 6 bytes of input turn into 7 bytes of "compressed" data. |
| 75 | // |
| 76 | // This last factor dominates the blowup, so the final estimate is: |
| 77 | return 32 + source_len + source_len/6; |
| 78 | } |
| 79 | |
| 80 | enum { |
| 81 | LITERAL = 0, |
no outgoing calls