validateNorm validates the normalized histogram table.
()
| 455 | |
| 456 | // validateNorm validates the normalized histogram table. |
| 457 | func (s *fseEncoder) validateNorm() (err error) { |
| 458 | var total int |
| 459 | for _, v := range s.norm[:s.symbolLen] { |
| 460 | if v >= 0 { |
| 461 | total += int(v) |
| 462 | } else { |
| 463 | total -= int(v) |
| 464 | } |
| 465 | } |
| 466 | defer func() { |
| 467 | if err == nil { |
| 468 | return |
| 469 | } |
| 470 | fmt.Printf("selected TableLog: %d, Symbol length: %d\n", s.actualTableLog, s.symbolLen) |
| 471 | for i, v := range s.norm[:s.symbolLen] { |
| 472 | fmt.Printf("%3d: %5d -> %4d \n", i, s.count[i], v) |
| 473 | } |
| 474 | }() |
| 475 | if total != (1 << s.actualTableLog) { |
| 476 | return fmt.Errorf("warning: Total == %d != %d", total, 1<<s.actualTableLog) |
| 477 | } |
| 478 | for i, v := range s.count[s.symbolLen:] { |
| 479 | if v != 0 { |
| 480 | return fmt.Errorf("warning: Found symbol out of range, %d after cut", i) |
| 481 | } |
| 482 | } |
| 483 | return nil |
| 484 | } |
| 485 | |
| 486 | // writeCount will write the normalized histogram count to header. |
| 487 | // This is read back by readNCount. |