writeCount will write the normalized histogram count to header. This is read back by readNCount.
(out []byte)
| 486 | // writeCount will write the normalized histogram count to header. |
| 487 | // This is read back by readNCount. |
| 488 | func (s *fseEncoder) writeCount(out []byte) ([]byte, error) { |
| 489 | if s.useRLE { |
| 490 | return append(out, s.rleVal), nil |
| 491 | } |
| 492 | if s.preDefined || s.reUsed { |
| 493 | // Never write predefined. |
| 494 | return out, nil |
| 495 | } |
| 496 | |
| 497 | var ( |
| 498 | tableLog = s.actualTableLog |
| 499 | tableSize = 1 << tableLog |
| 500 | previous0 bool |
| 501 | charnum uint16 |
| 502 | |
| 503 | // maximum header size plus 2 extra bytes for final output if bitCount == 0. |
| 504 | maxHeaderSize = ((int(s.symbolLen) * int(tableLog)) >> 3) + 3 + 2 |
| 505 | |
| 506 | // Write Table Size |
| 507 | bitStream = uint32(tableLog - minEncTablelog) |
| 508 | bitCount = uint(4) |
| 509 | remaining = int16(tableSize + 1) /* +1 for extra accuracy */ |
| 510 | threshold = int16(tableSize) |
| 511 | nbBits = uint(tableLog + 1) |
| 512 | outP = len(out) |
| 513 | ) |
| 514 | if cap(out) < outP+maxHeaderSize { |
| 515 | out = append(out, make([]byte, maxHeaderSize*3)...) |
| 516 | out = out[:len(out)-maxHeaderSize*3] |
| 517 | } |
| 518 | out = out[:outP+maxHeaderSize] |
| 519 | |
| 520 | // stops at 1 |
| 521 | for remaining > 1 { |
| 522 | if previous0 { |
| 523 | start := charnum |
| 524 | for s.norm[charnum] == 0 { |
| 525 | charnum++ |
| 526 | } |
| 527 | for charnum >= start+24 { |
| 528 | start += 24 |
| 529 | bitStream += uint32(0xFFFF) << bitCount |
| 530 | out[outP] = byte(bitStream) |
| 531 | out[outP+1] = byte(bitStream >> 8) |
| 532 | outP += 2 |
| 533 | bitStream >>= 16 |
| 534 | } |
| 535 | for charnum >= start+3 { |
| 536 | start += 3 |
| 537 | bitStream += 3 << bitCount |
| 538 | bitCount += 2 |
| 539 | } |
| 540 | bitStream += uint32(charnum-start) << bitCount |
| 541 | bitCount += 2 |
| 542 | if bitCount > 16 { |
| 543 | out[outP] = byte(bitStream) |
| 544 | out[outP+1] = byte(bitStream >> 8) |
| 545 | outP += 2 |
no outgoing calls
no test coverage detected