package brotliimport/* Copyright 2016 Google Inc. All Rights Reserved. Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT*/func (*h10) () uint {return4}func (*h10) () uint {return128}func hashBytesH10( []byte) uint32 {varuint32 = binary.LittleEndian.Uint32() * kHashMul32/* The higher bits contain more mixture from the multiplication, so we take our results from there. */return >> (32 - 17)}/* A (forgetful) hash table where each hash bucket contains a binary tree of sequences whose first 4 bytes share the same hash code. Each sequence is 128 long and is identified by its starting position in the input data. The binary tree is sorted by the lexicographic order of the sequences, and it is also a max-heap with respect to the starting positions. */type h10 struct {hasherCommon window_mask_ uint buckets_ [1 << 17]uint32 invalid_pos_ uint32 forest []uint32}func ( *h10) ( *encoderParams) { .window_mask_ = (1 << .lgwin) - 1 .invalid_pos_ = uint32(0 - .window_mask_)varuint = uint(1) << .lgwin .forest = make([]uint32, 2*)}func ( *h10) ( bool, uint, []byte) {varuint32 = .invalid_pos_varuint32for = 0; < 1<<17; ++ { .buckets_[] = }}func leftChildIndexH10( *h10, uint) uint {return2 * ( & .window_mask_)}func rightChildIndexH10( *h10, uint) uint {return2*(&.window_mask_) + 1}/* Stores the hash of the next 4 bytes and in a single tree-traversal, the hash bucket's binary tree is searched for matches and is re-rooted at the current position. If less than 128 data is available, the hash bucket of the current position is searched for matches, but the state of the hash table is not changed, since we can not know the final sorting order of the current (incomplete) sequence. This function must be called with increasing cur_ix positions. */func storeAndFindMatchesH10( *h10, []byte, uint, uint, uint, uint, *uint, []backwardMatch) []backwardMatch {varuint = & varuint = brotli_min_size_t(, 128)varbool = ( >= 128)varuint32 = hashBytesH10([:])var []uint32 = .forestvaruint = uint(.buckets_[])varuint = leftChildIndexH10(, )varuint = rightChildIndexH10(, )varuint = 0varuint = 0varuint/* The forest index of the rightmost node of the left subtree of the new root, updated as we traverse and re-root the tree of the hash bucket. *//* The forest index of the leftmost node of the right subtree of the new root, updated as we traverse and re-root the tree of the hash bucket. *//* The match length of the rightmost node of the left subtree of the new root, updated as we traverse and re-root the tree of the hash bucket. *//* The match length of the leftmost node of the right subtree of the new root, updated as we traverse and re-root the tree of the hash bucket. */if { .buckets_[] = uint32() }for = 64; ; -- {varuint = - varuint = & if == 0 || > || == 0 {if { [] = .invalid_pos_ [] = .invalid_pos_ }break } {varuint = brotli_min_size_t(, )varuintassert( <= 128) = + findMatchLengthWithLimit([+:], [+:], -)if != nil && > * { * = uint()initBackwardMatch(&[0], , uint()) = [1:] }if >= {if { [] = [leftChildIndexH10(, )] [] = [rightChildIndexH10(, )] }break }if [+] > [+] { = uint()if { [] = uint32() } = rightChildIndexH10(, ) = uint([]) } else { = uint()if { [] = uint32() } = leftChildIndexH10(, ) = uint([]) } } }return}/* Finds all backward matches of &data[cur_ix & ring_buffer_mask] up to the length of max_length and stores the position cur_ix in the hash table. Sets *num_matches to the number of matches found, and stores the found matches in matches[0] to matches[*num_matches - 1]. The matches will be sorted by strictly increasing length and (non-strictly) increasing distance. */func findAllMatchesH10( *h10, *encoderDictionary, []byte, uint, uint, uint, uint, uint, *encoderParams, []backwardMatch) uint {var []backwardMatch = varuint = & varuint = 1varuintif .quality != hqZopflificationQuality { = 16 } else { = 64 }varuint = - var [maxStaticDictionaryMatchLen + 1]uint32varuintif < { = 0 }for = - 1; > && <= 2; -- {varuint = varuint = - if > {break } &= if [] != [] || [+1] != [+1] {continue } {varuint = findMatchLengthWithLimit([:], [:], )if > { = uint()initBackwardMatch(&[0], , uint()) = [1:] } } }if < { = storeAndFindMatchesH10(, , , , , , &, ) }for = 0; <= maxStaticDictionaryMatchLen; ++ { [] = kInvalidMatch } {varuint = brotli_max_size_t(4, +1)iffindAllStaticDictionaryMatches(, [:], , , [0:]) {varuint = brotli_min_size_t(maxStaticDictionaryMatchLen, )varuintfor = ; <= ; ++ {varuint32 = []if < kInvalidMatch {varuint = + + uint(>>5) + 1if <= .dist.max_distance {initDictionaryBackwardMatch(&[0], , , uint(&31)) = [1:] } } } } }returnuint(-cap() + cap())}/* Stores the hash of the next 4 bytes and re-roots the binary tree at the current sequence, without returning any matches. REQUIRES: ix + 128 <= end-of-current-block */func ( *h10) ( []byte, uint, uint) {varuint = .window_mask_ - windowGap + 1/* Maximum distance is window size - 16, see section 9.1. of the spec. */storeAndFindMatchesH10(, , , , 128, , nil, nil)}func ( *h10) ( []byte, uint, uint, uint) {varuint = varuint = if +63 <= { = - 63 }if +512 <= {for ; < ; += 8 { .Store(, , ) } }for ; < ; ++ { .Store(, , ) }}func ( *h10) ( uint, uint, []byte, uint) {if >= .HashTypeLength()-1 && >= 128 {varuint = - 128 + 1varuint = brotli_min_size_t(, +)/* Store the last `128 - 1` positions in the hasher. These could not be calculated before, since they require knowledge of both the previous and the current block. */varuintfor = ; < ; ++ {/* Maximum distance is window size - 16, see section 9.1. of the spec. Furthermore, we have to make sure that we don't look further back from the start of the next block than the window size, otherwise we could access already overwritten areas of the ring-buffer. */varuint = .window_mask_ - brotli_max_size_t(windowGap-1, -)/* We know that i + 128 <= position + num_bytes, i.e. the end of the current block and that we have at least 128 tail in the ring-buffer. */storeAndFindMatchesH10(, , , , 128, , nil, nil) } }}/* MAX_NUM_MATCHES == 64 + MAX_TREE_SEARCH_DEPTH */const maxNumMatchesH10 = 128func (*h10) ( *encoderDictionary, []byte, uint, []int, uint, uint, uint, uint, uint, *hasherSearchResult) {panic("unimplemented")}func (*h10) ( []int) {panic("unimplemented")}
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.