()
| 21 | var totalbits = 0 |
| 22 | |
| 23 | func (s *State) Encode() []byte { |
| 24 | enc := arith.NewEncoder() |
| 25 | |
| 26 | historic := s.Historic().Cubes |
| 27 | baseline := s.Baseline().Cubes |
| 28 | current := s.Current().Cubes |
| 29 | |
| 30 | mzeros := mZeros() |
| 31 | items := []int{} |
| 32 | for i := range current { |
| 33 | cube, base := ¤t[i], &baseline[i] |
| 34 | if *cube == *base { |
| 35 | mzeros.Encode(enc, 0) |
| 36 | } else { |
| 37 | mzeros.Encode(enc, 1) |
| 38 | items = append(items, i) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | for _, i := range items { |
| 43 | cube := ¤t[i] |
| 44 | mzeros.Encode(enc, uint(cube.Interacting^1)) |
| 45 | } |
| 46 | |
| 47 | for _, i := range items { |
| 48 | cube, base := ¤t[i], &baseline[i] |
| 49 | v := uint(cube.Largest ^ base.Largest) |
| 50 | mzeros.Encode(enc, v&1) |
| 51 | mzeros.Encode(enc, v>>1) |
| 52 | } |
| 53 | |
| 54 | items6 := Index6(items, len(baseline)) |
| 55 | SortByZ(items6, Delta6(historic, baseline)) |
| 56 | get6 := Extra6(historic, baseline, current) |
| 57 | |
| 58 | max := uint64(0) |
| 59 | for _, i := range items6 { |
| 60 | ext := uint64(bit.ZEncode(int64(get6(i)))) |
| 61 | if max < ext { |
| 62 | max = ext |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if max == 0 { |
| 67 | mzeros.Encode(enc, 1) |
| 68 | enc.Close() |
| 69 | return enc.Bytes() |
| 70 | } |
| 71 | |
| 72 | nbits := bit.ScanRight(max) + 1 |
| 73 | for i := 0; i < int(nbits); i += 1 { |
| 74 | mzeros.Encode(enc, 0) |
| 75 | } |
| 76 | mzeros.Encode(enc, 1) |
| 77 | |
| 78 | mvalues := mValues(nbits) |
| 79 | for _, i := range items6 { |
| 80 | val := uint(bit.ZEncode(int64(get6(i)))) |
no test coverage detected