github.com/andybalholm/brotli@v1.0.6/cluster.go (about)

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