Skip to content

Commit

Permalink
Start un-exporting names.
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalholm committed Mar 10, 2019
1 parent 1ce1c68 commit 5001b3d
Show file tree
Hide file tree
Showing 18 changed files with 352 additions and 362 deletions.
6 changes: 3 additions & 3 deletions backward_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package brotli
initially the total amount of commands output by previous
CreateBackwardReferences calls, and must be incremented by the amount written
by this call. */
func ComputeDistanceCode(distance uint, max_distance uint, dist_cache []int) uint {
func computeDistanceCode(distance uint, max_distance uint, dist_cache []int) uint {
if distance <= max_distance {
var distance_plus_3 uint = distance + 3
var offset0 uint = distance_plus_3 - uint(dist_cache[0])
Expand All @@ -42,7 +42,7 @@ func ComputeDistanceCode(distance uint, max_distance uint, dist_cache []int) uin
return distance + BROTLI_NUM_DISTANCE_SHORT_CODES - 1
}

func BrotliCreateBackwardReferences(num_bytes uint, position uint, ringbuffer []byte, ringbuffer_mask uint, params *BrotliEncoderParams, hasher HasherHandle, dist_cache []int, last_insert_len *uint, commands []Command, num_commands *uint, num_literals *uint) {
func createBackwardReferences(num_bytes uint, position uint, ringbuffer []byte, ringbuffer_mask uint, params *BrotliEncoderParams, hasher HasherHandle, dist_cache []int, last_insert_len *uint, commands []Command, num_commands *uint, num_literals *uint) {
var max_backward_limit uint = BROTLI_MAX_BACKWARD_LIMIT(params.lgwin)
var orig_commands []Command = commands
var insert_length uint = *last_insert_len
Expand Down Expand Up @@ -112,7 +112,7 @@ func BrotliCreateBackwardReferences(num_bytes uint, position uint, ringbuffer []
{
/* The first 16 codes are special short-codes,
and the minimum offset is 1. */
var distance_code uint = ComputeDistanceCode(sr.distance, max_distance+gap, dist_cache)
var distance_code uint = computeDistanceCode(sr.distance, max_distance+gap, dist_cache)
if (sr.distance <= (max_distance + gap)) && distance_code > 0 {
dist_cache[3] = dist_cache[2]
dist_cache[2] = dist_cache[1]
Expand Down
222 changes: 111 additions & 111 deletions backward_references_hq.go

Large diffs are not rendered by default.

66 changes: 28 additions & 38 deletions bit_cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package brotli
*/

/* Functions to estimate the bit cost of Huffman trees. */
func ShannonEntropy(population []uint32, size uint, total *uint) float64 {
func shannonEntropy(population []uint32, size uint, total *uint) float64 {
var sum uint = 0
var retval float64 = 0
var population_end []uint32 = population[size:]
Expand All @@ -33,9 +33,9 @@ func ShannonEntropy(population []uint32, size uint, total *uint) float64 {
return retval
}

func BitsEntropy(population []uint32, size uint) float64 {
func bitsEntropy(population []uint32, size uint) float64 {
var sum uint
var retval float64 = ShannonEntropy(population, size, &sum)
var retval float64 = shannonEntropy(population, size, &sum)
if retval < float64(sum) {
/* At least one bit per literal is needed. */
retval = float64(sum)
Expand All @@ -44,19 +44,19 @@ func BitsEntropy(population []uint32, size uint) float64 {
return retval
}

var BrotliPopulationCostLiteral_kOneSymbolHistogramCost float64 = 12
var BrotliPopulationCostLiteral_kTwoSymbolHistogramCost float64 = 20
var BrotliPopulationCostLiteral_kThreeSymbolHistogramCost float64 = 28
var BrotliPopulationCostLiteral_kFourSymbolHistogramCost float64 = 37
const kOneSymbolHistogramCost float64 = 12
const kTwoSymbolHistogramCost float64 = 20
const kThreeSymbolHistogramCost float64 = 28
const kFourSymbolHistogramCost float64 = 37

func BrotliPopulationCostLiteral(histogram *HistogramLiteral) float64 {
func populationCostLiteral(histogram *HistogramLiteral) float64 {
var data_size uint = HistogramDataSizeLiteral()
var count int = 0
var s [5]uint
var bits float64 = 0.0
var i uint
if histogram.total_count_ == 0 {
return BrotliPopulationCostLiteral_kOneSymbolHistogramCost
return kOneSymbolHistogramCost
}

for i = 0; i < data_size; i++ {
Expand All @@ -70,19 +70,19 @@ func BrotliPopulationCostLiteral(histogram *HistogramLiteral) float64 {
}

if count == 1 {
return BrotliPopulationCostLiteral_kOneSymbolHistogramCost
return kOneSymbolHistogramCost
}

if count == 2 {
return BrotliPopulationCostLiteral_kTwoSymbolHistogramCost + float64(histogram.total_count_)
return kTwoSymbolHistogramCost + float64(histogram.total_count_)
}

if count == 3 {
var histo0 uint32 = histogram.data_[s[0]]
var histo1 uint32 = histogram.data_[s[1]]
var histo2 uint32 = histogram.data_[s[2]]
var histomax uint32 = brotli_max_uint32_t(histo0, brotli_max_uint32_t(histo1, histo2))
return BrotliPopulationCostLiteral_kThreeSymbolHistogramCost + 2*(float64(histo0)+float64(histo1)+float64(histo2)) - float64(histomax)
return kThreeSymbolHistogramCost + 2*(float64(histo0)+float64(histo1)+float64(histo2)) - float64(histomax)
}

if count == 4 {
Expand All @@ -107,7 +107,7 @@ func BrotliPopulationCostLiteral(histogram *HistogramLiteral) float64 {

h23 = histo[2] + histo[3]
histomax = brotli_max_uint32_t(h23, histo[0])
return BrotliPopulationCostLiteral_kFourSymbolHistogramCost + 3*float64(h23) + 2*(float64(histo[0])+float64(histo[1])) - float64(histomax)
return kFourSymbolHistogramCost + 3*float64(h23) + 2*(float64(histo[0])+float64(histo[1])) - float64(histomax)
}
{
var max_depth uint = 1
Expand Down Expand Up @@ -174,25 +174,20 @@ func BrotliPopulationCostLiteral(histogram *HistogramLiteral) float64 {
bits += float64(18 + 2*max_depth)

/* Add the entropy of the code length code histogram. */
bits += BitsEntropy(depth_histo[:], BROTLI_CODE_LENGTH_CODES)
bits += bitsEntropy(depth_histo[:], BROTLI_CODE_LENGTH_CODES)
}

return bits
}

var BrotliPopulationCostCommand_kOneSymbolHistogramCost float64 = 12
var BrotliPopulationCostCommand_kTwoSymbolHistogramCost float64 = 20
var BrotliPopulationCostCommand_kThreeSymbolHistogramCost float64 = 28
var BrotliPopulationCostCommand_kFourSymbolHistogramCost float64 = 37

func BrotliPopulationCostCommand(histogram *HistogramCommand) float64 {
func populationCostCommand(histogram *HistogramCommand) float64 {
var data_size uint = HistogramDataSizeCommand()
var count int = 0
var s [5]uint
var bits float64 = 0.0
var i uint
if histogram.total_count_ == 0 {
return BrotliPopulationCostCommand_kOneSymbolHistogramCost
return kOneSymbolHistogramCost
}

for i = 0; i < data_size; i++ {
Expand All @@ -206,19 +201,19 @@ func BrotliPopulationCostCommand(histogram *HistogramCommand) float64 {
}

if count == 1 {
return BrotliPopulationCostCommand_kOneSymbolHistogramCost
return kOneSymbolHistogramCost
}

if count == 2 {
return BrotliPopulationCostCommand_kTwoSymbolHistogramCost + float64(histogram.total_count_)
return kTwoSymbolHistogramCost + float64(histogram.total_count_)
}

if count == 3 {
var histo0 uint32 = histogram.data_[s[0]]
var histo1 uint32 = histogram.data_[s[1]]
var histo2 uint32 = histogram.data_[s[2]]
var histomax uint32 = brotli_max_uint32_t(histo0, brotli_max_uint32_t(histo1, histo2))
return BrotliPopulationCostCommand_kThreeSymbolHistogramCost + 2*(float64(histo0)+float64(histo1)+float64(histo2)) - float64(histomax)
return kThreeSymbolHistogramCost + 2*(float64(histo0)+float64(histo1)+float64(histo2)) - float64(histomax)
}

if count == 4 {
Expand All @@ -243,7 +238,7 @@ func BrotliPopulationCostCommand(histogram *HistogramCommand) float64 {

h23 = histo[2] + histo[3]
histomax = brotli_max_uint32_t(h23, histo[0])
return BrotliPopulationCostCommand_kFourSymbolHistogramCost + 3*float64(h23) + 2*(float64(histo[0])+float64(histo[1])) - float64(histomax)
return kFourSymbolHistogramCost + 3*float64(h23) + 2*(float64(histo[0])+float64(histo[1])) - float64(histomax)
}
{
var max_depth uint = 1
Expand Down Expand Up @@ -310,25 +305,20 @@ func BrotliPopulationCostCommand(histogram *HistogramCommand) float64 {
bits += float64(18 + 2*max_depth)

/* Add the entropy of the code length code histogram. */
bits += BitsEntropy(depth_histo[:], BROTLI_CODE_LENGTH_CODES)
bits += bitsEntropy(depth_histo[:], BROTLI_CODE_LENGTH_CODES)
}

return bits
}

var BrotliPopulationCostDistance_kOneSymbolHistogramCost float64 = 12
var BrotliPopulationCostDistance_kTwoSymbolHistogramCost float64 = 20
var BrotliPopulationCostDistance_kThreeSymbolHistogramCost float64 = 28
var BrotliPopulationCostDistance_kFourSymbolHistogramCost float64 = 37

func BrotliPopulationCostDistance(histogram *HistogramDistance) float64 {
func populationCostDistance(histogram *HistogramDistance) float64 {
var data_size uint = HistogramDataSizeDistance()
var count int = 0
var s [5]uint
var bits float64 = 0.0
var i uint
if histogram.total_count_ == 0 {
return BrotliPopulationCostDistance_kOneSymbolHistogramCost
return kOneSymbolHistogramCost
}

for i = 0; i < data_size; i++ {
Expand All @@ -342,19 +332,19 @@ func BrotliPopulationCostDistance(histogram *HistogramDistance) float64 {
}

if count == 1 {
return BrotliPopulationCostDistance_kOneSymbolHistogramCost
return kOneSymbolHistogramCost
}

if count == 2 {
return BrotliPopulationCostDistance_kTwoSymbolHistogramCost + float64(histogram.total_count_)
return kTwoSymbolHistogramCost + float64(histogram.total_count_)
}

if count == 3 {
var histo0 uint32 = histogram.data_[s[0]]
var histo1 uint32 = histogram.data_[s[1]]
var histo2 uint32 = histogram.data_[s[2]]
var histomax uint32 = brotli_max_uint32_t(histo0, brotli_max_uint32_t(histo1, histo2))
return BrotliPopulationCostDistance_kThreeSymbolHistogramCost + 2*(float64(histo0)+float64(histo1)+float64(histo2)) - float64(histomax)
return kThreeSymbolHistogramCost + 2*(float64(histo0)+float64(histo1)+float64(histo2)) - float64(histomax)
}

if count == 4 {
Expand All @@ -379,7 +369,7 @@ func BrotliPopulationCostDistance(histogram *HistogramDistance) float64 {

h23 = histo[2] + histo[3]
histomax = brotli_max_uint32_t(h23, histo[0])
return BrotliPopulationCostDistance_kFourSymbolHistogramCost + 3*float64(h23) + 2*(float64(histo[0])+float64(histo[1])) - float64(histomax)
return kFourSymbolHistogramCost + 3*float64(h23) + 2*(float64(histo[0])+float64(histo[1])) - float64(histomax)
}
{
var max_depth uint = 1
Expand Down Expand Up @@ -446,7 +436,7 @@ func BrotliPopulationCostDistance(histogram *HistogramDistance) float64 {
bits += float64(18 + 2*max_depth)

/* Add the entropy of the code length code histogram. */
bits += BitsEntropy(depth_histo[:], BROTLI_CODE_LENGTH_CODES)
bits += bitsEntropy(depth_histo[:], BROTLI_CODE_LENGTH_CODES)
}

return bits
Expand Down
Loading

0 comments on commit 5001b3d

Please sign in to comment.