Scott Baker | ed4efab | 2020-01-13 19:12:25 -0800 | [diff] [blame] | 1 | // Copyright 2019+ Klaus Post. All rights reserved. |
| 2 | // License information can be found in the LICENSE file. |
| 3 | // Based on work by Yann Collet, released under BSD License. |
| 4 | |
| 5 | package zstd |
| 6 | |
| 7 | type encParams struct { |
| 8 | // largest match distance : larger == more compression, more memory needed during decompression |
| 9 | windowLog uint8 |
| 10 | |
| 11 | // fully searched segment : larger == more compression, slower, more memory (useless for fast) |
| 12 | chainLog uint8 |
| 13 | |
| 14 | // dispatch table : larger == faster, more memory |
| 15 | hashLog uint8 |
| 16 | |
| 17 | // < nb of searches : larger == more compression, slower |
| 18 | searchLog uint8 |
| 19 | |
| 20 | // < match length searched : larger == faster decompression, sometimes less compression |
| 21 | minMatch uint8 |
| 22 | |
| 23 | // acceptable match size for optimal parser (only) : larger == more compression, slower |
| 24 | targetLength uint32 |
| 25 | |
| 26 | // see ZSTD_strategy definition above |
| 27 | strategy strategy |
| 28 | } |
| 29 | |
| 30 | // strategy defines the algorithm to use when generating sequences. |
| 31 | type strategy uint8 |
| 32 | |
| 33 | const ( |
| 34 | // Compression strategies, listed from fastest to strongest |
| 35 | strategyFast strategy = iota + 1 |
| 36 | strategyDfast |
| 37 | strategyGreedy |
| 38 | strategyLazy |
| 39 | strategyLazy2 |
| 40 | strategyBtlazy2 |
| 41 | strategyBtopt |
| 42 | strategyBtultra |
| 43 | strategyBtultra2 |
| 44 | // note : new strategies _might_ be added in the future. |
| 45 | // Only the order (from fast to strong) is guaranteed |
| 46 | |
| 47 | ) |
| 48 | |
| 49 | var defEncParams = [4][]encParams{ |
| 50 | { // "default" - for any srcSize > 256 KB |
| 51 | // W, C, H, S, L, TL, strat |
| 52 | {19, 12, 13, 1, 6, 1, strategyFast}, // base for negative levels |
| 53 | {19, 13, 14, 1, 7, 0, strategyFast}, // level 1 |
| 54 | {20, 15, 16, 1, 6, 0, strategyFast}, // level 2 |
| 55 | {21, 16, 17, 1, 5, 1, strategyDfast}, // level 3 |
| 56 | {21, 18, 18, 1, 5, 1, strategyDfast}, // level 4 |
| 57 | {21, 18, 19, 2, 5, 2, strategyGreedy}, // level 5 |
| 58 | {21, 19, 19, 3, 5, 4, strategyGreedy}, // level 6 |
| 59 | {21, 19, 19, 3, 5, 8, strategyLazy}, // level 7 |
| 60 | {21, 19, 19, 3, 5, 16, strategyLazy2}, // level 8 |
| 61 | {21, 19, 20, 4, 5, 16, strategyLazy2}, // level 9 |
| 62 | {22, 20, 21, 4, 5, 16, strategyLazy2}, // level 10 |
| 63 | {22, 21, 22, 4, 5, 16, strategyLazy2}, // level 11 |
| 64 | {22, 21, 22, 5, 5, 16, strategyLazy2}, // level 12 |
| 65 | {22, 21, 22, 5, 5, 32, strategyBtlazy2}, // level 13 |
| 66 | {22, 22, 23, 5, 5, 32, strategyBtlazy2}, // level 14 |
| 67 | {22, 23, 23, 6, 5, 32, strategyBtlazy2}, // level 15 |
| 68 | {22, 22, 22, 5, 5, 48, strategyBtopt}, // level 16 |
| 69 | {23, 23, 22, 5, 4, 64, strategyBtopt}, // level 17 |
| 70 | {23, 23, 22, 6, 3, 64, strategyBtultra}, // level 18 |
| 71 | {23, 24, 22, 7, 3, 256, strategyBtultra2}, // level 19 |
| 72 | {25, 25, 23, 7, 3, 256, strategyBtultra2}, // level 20 |
| 73 | {26, 26, 24, 7, 3, 512, strategyBtultra2}, // level 21 |
| 74 | {27, 27, 25, 9, 3, 999, strategyBtultra2}, // level 22 |
| 75 | }, |
| 76 | { // for srcSize <= 256 KB |
| 77 | // W, C, H, S, L, T, strat |
| 78 | {18, 12, 13, 1, 5, 1, strategyFast}, // base for negative levels |
| 79 | {18, 13, 14, 1, 6, 0, strategyFast}, // level 1 |
| 80 | {18, 14, 14, 1, 5, 1, strategyDfast}, // level 2 |
| 81 | {18, 16, 16, 1, 4, 1, strategyDfast}, // level 3 |
| 82 | {18, 16, 17, 2, 5, 2, strategyGreedy}, // level 4. |
| 83 | {18, 18, 18, 3, 5, 2, strategyGreedy}, // level 5. |
| 84 | {18, 18, 19, 3, 5, 4, strategyLazy}, // level 6. |
| 85 | {18, 18, 19, 4, 4, 4, strategyLazy}, // level 7 |
| 86 | {18, 18, 19, 4, 4, 8, strategyLazy2}, // level 8 |
| 87 | {18, 18, 19, 5, 4, 8, strategyLazy2}, // level 9 |
| 88 | {18, 18, 19, 6, 4, 8, strategyLazy2}, // level 10 |
| 89 | {18, 18, 19, 5, 4, 12, strategyBtlazy2}, // level 11. |
| 90 | {18, 19, 19, 7, 4, 12, strategyBtlazy2}, // level 12. |
| 91 | {18, 18, 19, 4, 4, 16, strategyBtopt}, // level 13 |
| 92 | {18, 18, 19, 4, 3, 32, strategyBtopt}, // level 14. |
| 93 | {18, 18, 19, 6, 3, 128, strategyBtopt}, // level 15. |
| 94 | {18, 19, 19, 6, 3, 128, strategyBtultra}, // level 16. |
| 95 | {18, 19, 19, 8, 3, 256, strategyBtultra}, // level 17. |
| 96 | {18, 19, 19, 6, 3, 128, strategyBtultra2}, // level 18. |
| 97 | {18, 19, 19, 8, 3, 256, strategyBtultra2}, // level 19. |
| 98 | {18, 19, 19, 10, 3, 512, strategyBtultra2}, // level 20. |
| 99 | {18, 19, 19, 12, 3, 512, strategyBtultra2}, // level 21. |
| 100 | {18, 19, 19, 13, 3, 999, strategyBtultra2}, // level 22. |
| 101 | }, |
| 102 | { // for srcSize <= 128 KB |
| 103 | // W, C, H, S, L, T, strat |
| 104 | {17, 12, 12, 1, 5, 1, strategyFast}, // base for negative levels |
| 105 | {17, 12, 13, 1, 6, 0, strategyFast}, // level 1 |
| 106 | {17, 13, 15, 1, 5, 0, strategyFast}, // level 2 |
| 107 | {17, 15, 16, 2, 5, 1, strategyDfast}, // level 3 |
| 108 | {17, 17, 17, 2, 4, 1, strategyDfast}, // level 4 |
| 109 | {17, 16, 17, 3, 4, 2, strategyGreedy}, // level 5 |
| 110 | {17, 17, 17, 3, 4, 4, strategyLazy}, // level 6 |
| 111 | {17, 17, 17, 3, 4, 8, strategyLazy2}, // level 7 |
| 112 | {17, 17, 17, 4, 4, 8, strategyLazy2}, // level 8 |
| 113 | {17, 17, 17, 5, 4, 8, strategyLazy2}, // level 9 |
| 114 | {17, 17, 17, 6, 4, 8, strategyLazy2}, // level 10 |
| 115 | {17, 17, 17, 5, 4, 8, strategyBtlazy2}, // level 11 |
| 116 | {17, 18, 17, 7, 4, 12, strategyBtlazy2}, // level 12 |
| 117 | {17, 18, 17, 3, 4, 12, strategyBtopt}, // level 13. |
| 118 | {17, 18, 17, 4, 3, 32, strategyBtopt}, // level 14. |
| 119 | {17, 18, 17, 6, 3, 256, strategyBtopt}, // level 15. |
| 120 | {17, 18, 17, 6, 3, 128, strategyBtultra}, // level 16. |
| 121 | {17, 18, 17, 8, 3, 256, strategyBtultra}, // level 17. |
| 122 | {17, 18, 17, 10, 3, 512, strategyBtultra}, // level 18. |
| 123 | {17, 18, 17, 5, 3, 256, strategyBtultra2}, // level 19. |
| 124 | {17, 18, 17, 7, 3, 512, strategyBtultra2}, // level 20. |
| 125 | {17, 18, 17, 9, 3, 512, strategyBtultra2}, // level 21. |
| 126 | {17, 18, 17, 11, 3, 999, strategyBtultra2}, // level 22. |
| 127 | }, |
| 128 | { // for srcSize <= 16 KB |
| 129 | // W, C, H, S, L, T, strat |
| 130 | {14, 12, 13, 1, 5, 1, strategyFast}, // base for negative levels |
| 131 | {14, 14, 15, 1, 5, 0, strategyFast}, // level 1 |
| 132 | {14, 14, 15, 1, 4, 0, strategyFast}, // level 2 |
| 133 | {14, 14, 15, 2, 4, 1, strategyDfast}, // level 3 |
| 134 | {14, 14, 14, 4, 4, 2, strategyGreedy}, // level 4 |
| 135 | {14, 14, 14, 3, 4, 4, strategyLazy}, // level 5. |
| 136 | {14, 14, 14, 4, 4, 8, strategyLazy2}, // level 6 |
| 137 | {14, 14, 14, 6, 4, 8, strategyLazy2}, // level 7 |
| 138 | {14, 14, 14, 8, 4, 8, strategyLazy2}, // level 8. |
| 139 | {14, 15, 14, 5, 4, 8, strategyBtlazy2}, // level 9. |
| 140 | {14, 15, 14, 9, 4, 8, strategyBtlazy2}, // level 10. |
| 141 | {14, 15, 14, 3, 4, 12, strategyBtopt}, // level 11. |
| 142 | {14, 15, 14, 4, 3, 24, strategyBtopt}, // level 12. |
| 143 | {14, 15, 14, 5, 3, 32, strategyBtultra}, // level 13. |
| 144 | {14, 15, 15, 6, 3, 64, strategyBtultra}, // level 14. |
| 145 | {14, 15, 15, 7, 3, 256, strategyBtultra}, // level 15. |
| 146 | {14, 15, 15, 5, 3, 48, strategyBtultra2}, // level 16. |
| 147 | {14, 15, 15, 6, 3, 128, strategyBtultra2}, // level 17. |
| 148 | {14, 15, 15, 7, 3, 256, strategyBtultra2}, // level 18. |
| 149 | {14, 15, 15, 8, 3, 256, strategyBtultra2}, // level 19. |
| 150 | {14, 15, 15, 8, 3, 512, strategyBtultra2}, // level 20. |
| 151 | {14, 15, 15, 9, 3, 512, strategyBtultra2}, // level 21. |
| 152 | {14, 15, 15, 10, 3, 999, strategyBtultra2}, // level 22. |
| 153 | }, |
| 154 | } |