1 | package brotli
|
---|
2 |
|
---|
3 | /* Copyright 2018 Google Inc. All Rights Reserved.
|
---|
4 |
|
---|
5 | Distributed under MIT license.
|
---|
6 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
---|
7 | */
|
---|
8 |
|
---|
9 | func (h *hashComposite) HashTypeLength() uint {
|
---|
10 | var a uint = h.ha.HashTypeLength()
|
---|
11 | var b uint = h.hb.HashTypeLength()
|
---|
12 | if a > b {
|
---|
13 | return a
|
---|
14 | } else {
|
---|
15 | return b
|
---|
16 | }
|
---|
17 | }
|
---|
18 |
|
---|
19 | func (h *hashComposite) StoreLookahead() uint {
|
---|
20 | var a uint = h.ha.StoreLookahead()
|
---|
21 | var b uint = h.hb.StoreLookahead()
|
---|
22 | if a > b {
|
---|
23 | return a
|
---|
24 | } else {
|
---|
25 | return b
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | /* Composite hasher: This hasher allows to combine two other hashers, HASHER_A
|
---|
30 | and HASHER_B. */
|
---|
31 | type hashComposite struct {
|
---|
32 | hasherCommon
|
---|
33 | ha hasherHandle
|
---|
34 | hb hasherHandle
|
---|
35 | params *encoderParams
|
---|
36 | }
|
---|
37 |
|
---|
38 | func (h *hashComposite) Initialize(params *encoderParams) {
|
---|
39 | h.params = params
|
---|
40 | }
|
---|
41 |
|
---|
42 | /* TODO: Initialize of the hashers is defered to Prepare (and params
|
---|
43 | remembered here) because we don't get the one_shot and input_size params
|
---|
44 | here that are needed to know the memory size of them. Instead provide
|
---|
45 | those params to all hashers InitializehashComposite */
|
---|
46 | func (h *hashComposite) Prepare(one_shot bool, input_size uint, data []byte) {
|
---|
47 | if h.ha == nil {
|
---|
48 | var common_a *hasherCommon
|
---|
49 | var common_b *hasherCommon
|
---|
50 |
|
---|
51 | common_a = h.ha.Common()
|
---|
52 | common_a.params = h.params.hasher
|
---|
53 | common_a.is_prepared_ = false
|
---|
54 | common_a.dict_num_lookups = 0
|
---|
55 | common_a.dict_num_matches = 0
|
---|
56 | h.ha.Initialize(h.params)
|
---|
57 |
|
---|
58 | common_b = h.hb.Common()
|
---|
59 | common_b.params = h.params.hasher
|
---|
60 | common_b.is_prepared_ = false
|
---|
61 | common_b.dict_num_lookups = 0
|
---|
62 | common_b.dict_num_matches = 0
|
---|
63 | h.hb.Initialize(h.params)
|
---|
64 | }
|
---|
65 |
|
---|
66 | h.ha.Prepare(one_shot, input_size, data)
|
---|
67 | h.hb.Prepare(one_shot, input_size, data)
|
---|
68 | }
|
---|
69 |
|
---|
70 | func (h *hashComposite) Store(data []byte, mask uint, ix uint) {
|
---|
71 | h.ha.Store(data, mask, ix)
|
---|
72 | h.hb.Store(data, mask, ix)
|
---|
73 | }
|
---|
74 |
|
---|
75 | func (h *hashComposite) StoreRange(data []byte, mask uint, ix_start uint, ix_end uint) {
|
---|
76 | h.ha.StoreRange(data, mask, ix_start, ix_end)
|
---|
77 | h.hb.StoreRange(data, mask, ix_start, ix_end)
|
---|
78 | }
|
---|
79 |
|
---|
80 | func (h *hashComposite) StitchToPreviousBlock(num_bytes uint, position uint, ringbuffer []byte, ring_buffer_mask uint) {
|
---|
81 | h.ha.StitchToPreviousBlock(num_bytes, position, ringbuffer, ring_buffer_mask)
|
---|
82 | h.hb.StitchToPreviousBlock(num_bytes, position, ringbuffer, ring_buffer_mask)
|
---|
83 | }
|
---|
84 |
|
---|
85 | func (h *hashComposite) PrepareDistanceCache(distance_cache []int) {
|
---|
86 | h.ha.PrepareDistanceCache(distance_cache)
|
---|
87 | h.hb.PrepareDistanceCache(distance_cache)
|
---|
88 | }
|
---|
89 |
|
---|
90 | func (h *hashComposite) FindLongestMatch(dictionary *encoderDictionary, data []byte, ring_buffer_mask uint, distance_cache []int, cur_ix uint, max_length uint, max_backward uint, gap uint, max_distance uint, out *hasherSearchResult) {
|
---|
91 | h.ha.FindLongestMatch(dictionary, data, ring_buffer_mask, distance_cache, cur_ix, max_length, max_backward, gap, max_distance, out)
|
---|
92 | h.hb.FindLongestMatch(dictionary, data, ring_buffer_mask, distance_cache, cur_ix, max_length, max_backward, gap, max_distance, out)
|
---|
93 | }
|
---|