package brotlifunc utf8Position( uint, uint, uint) uint {if < 128 {return0/* Next one is the 'Byte 1' again. */ } elseif >= 192 { /* Next one is the 'Byte 2' of utf-8 encoding. */returnbrotli_min_size_t(1, ) } else {/* Let's decide over the last byte if this ends the sequence. */if < 0xE0 {return0/* Completed two or three byte coding. */ /* Next one is the 'Byte 3' of utf-8 encoding. */ } else {returnbrotli_min_size_t(2, ) } }}func decideMultiByteStatsLevel( uint, uint, uint, []byte) uint {var = [3]uint{0} /* should be 2, but 1 compresses better. */varuint = 1varuint = 0varuintfor = 0; < ; ++ {varuint = uint([(+)&]) [utf8Position(, , 2)]++ = }if [2] < 500 { = 1 }if [1]+[2] < 25 { = 0 }return}func estimateBitCostsForLiteralsUTF8( uint, uint, uint, []byte, []float32) {varuint = decideMultiByteStatsLevel(, uint(), , )/* Bootstrap histograms. */var = [3][256]uint{[256]uint{0}}varuint = 495varuint = brotli_min_size_t(, uint())var = [3]uint{0}/* max_utf8 is 0 (normal ASCII single byte modeling), 1 (for 2-byte UTF-8 modeling), or 2 (for 3-byte UTF-8 modeling). */varuint {varuint = 0varuint = 0for = 0; < ; ++ {varuint = uint([(+)&]) [][]++ []++ = utf8Position(, , ) = } }/* Compute bit costs with sliding window. */for = 0; < ; ++ {if >= {varuintvaruintif < +1 { = 0 } else { = uint([(+--1)&]) }if < +2 { = 0 } else { = uint([(+--2)&]) }/* Remove a byte in the past. */varuint = utf8Position(, , ) [][[(+-)&]]-- []-- }if + < {varuint = uint([(++-1)&])varuint = uint([(++-2)&])/* Add a byte in the future. */varuint = utf8Position(, , ) [][[(++)&]]++ []++ } {varuintvaruintif < 1 { = 0 } else { = uint([(+-1)&]) }if < 2 { = 0 } else { = uint([(+-2)&]) }varuint = utf8Position(, , )varuint = ( + ) & varuint = [][[]]varfloat64if == 0 { = 1 } = fastLog2([]) - fastLog2() += 0.02905if < 1.0 { *= 0.5 += 0.5 }/* Make the first bytes more expensive -- seems to help, not sure why. Perhaps because the entropy source is changing its properties rapidly in the beginning of the file, perhaps because the beginning of the data is a statistical "anomaly". */if < 2000 { += 0.7 - (float64(2000-) / 2000.0 * 0.35) } [] = float32() } }}func estimateBitCostsForLiterals( uint, uint, uint, []byte, []float32) {ifisMostlyUTF8(, , , uint(), kMinUTF8Ratio) {estimateBitCostsForLiteralsUTF8(, uint(), , , )return } else {var = [256]uint{0}varuint = 2000varuint = brotli_min_size_t(, uint())varuint/* Bootstrap histogram. */for = 0; < ; ++ { [[(+)&]]++ }/* Compute bit costs with sliding window. */for = 0; < ; ++ {varuintif >= {/* Remove a byte in the past. */ [[(+-)&]]-- -- }if + < {/* Add a byte in the future. */ [[(++)&]]++ ++ } = [[(+)&]]if == 0 { = 1 } {varfloat64 = fastLog2() - fastLog2() += 0.029if < 1.0 { *= 0.5 += 0.5 } [] = float32() } } }}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.