cluster.go 839 B

123456789101112131415161718192021222324252627282930
  1. package brotli
  2. /* Copyright 2013 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. /* Functions for clustering similar histograms together. */
  7. type histogramPair struct {
  8. idx1 uint32
  9. idx2 uint32
  10. cost_combo float64
  11. cost_diff float64
  12. }
  13. func histogramPairIsLess(p1 *histogramPair, p2 *histogramPair) bool {
  14. if p1.cost_diff != p2.cost_diff {
  15. return p1.cost_diff > p2.cost_diff
  16. }
  17. return (p1.idx2 - p1.idx1) > (p2.idx2 - p2.idx1)
  18. }
  19. /* Returns entropy reduction of the context map when we combine two clusters. */
  20. func clusterCostDiff(size_a uint, size_b uint) float64 {
  21. var size_c uint = size_a + size_b
  22. return float64(size_a)*fastLog2(size_a) + float64(size_b)*fastLog2(size_b) - float64(size_c)*fastLog2(size_c)
  23. }