hash_composite.go 2.9 KB

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