init initializes dictDecoder to have a sliding window dictionary of the given size. If a preset dict is provided, it will initialize the dictionary with the contents of dict.
(size int, dict []byte)
| 38 | // size. If a preset dict is provided, it will initialize the dictionary with |
| 39 | // the contents of dict. |
| 40 | func (dd *dictDecoder) init(size int, dict []byte) { |
| 41 | *dd = dictDecoder{hist: dd.hist} |
| 42 | |
| 43 | if cap(dd.hist) < size { |
| 44 | dd.hist = make([]byte, size) |
| 45 | } |
| 46 | dd.hist = dd.hist[:size] |
| 47 | |
| 48 | if len(dict) > len(dd.hist) { |
| 49 | dict = dict[len(dict)-len(dd.hist):] |
| 50 | } |
| 51 | dd.wrPos = copy(dd.hist, dict) |
| 52 | if dd.wrPos == len(dd.hist) { |
| 53 | dd.wrPos = 0 |
| 54 | dd.full = true |
| 55 | } |
| 56 | dd.rdPos = dd.wrPos |
| 57 | } |
| 58 | |
| 59 | // histSize reports the total amount of historical data in the dictionary. |
| 60 | func (dd *dictDecoder) histSize() int { |
no outgoing calls