()
| 34 | var totalbits = 0 |
| 35 | |
| 36 | func (s *State) Encode() []byte { |
| 37 | enc := arith.NewEncoder() |
| 38 | |
| 39 | historic := s.Historic().Cubes |
| 40 | _ = historic |
| 41 | baseline := s.Baseline().Cubes |
| 42 | current := s.Current().Cubes |
| 43 | |
| 44 | mzeros := mZeros() |
| 45 | items := []int{} |
| 46 | for i := range current { |
| 47 | cube, base := ¤t[i], &baseline[i] |
| 48 | if *cube == *base { |
| 49 | mzeros.Encode(enc, 0) |
| 50 | } else { |
| 51 | mzeros.Encode(enc, 1) |
| 52 | items = append(items, i) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | for _, i := range items { |
| 57 | cube := ¤t[i] |
| 58 | v := uint(1) |
| 59 | if cube.Interacting { |
| 60 | v = 0 |
| 61 | } |
| 62 | mzeros.Encode(enc, v) |
| 63 | } |
| 64 | |
| 65 | props := IndexProps(items, len(baseline)) |
| 66 | SortByZ(props, Props(baseline)) |
| 67 | getProp := Props(current) |
| 68 | |
| 69 | max := uint64(0) |
| 70 | for _, i := range props { |
| 71 | ext := uint64(bit.ZEncode(int64(getProp(i)))) |
| 72 | if max < ext { |
| 73 | max = ext |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if max == 0 { |
| 78 | mzeros.Encode(enc, 1) |
| 79 | enc.Close() |
| 80 | return enc.Bytes() |
| 81 | } |
| 82 | |
| 83 | nbits := bit.ScanRight(max) + 1 |
| 84 | for i := 0; i < int(nbits); i += 1 { |
| 85 | mzeros.Encode(enc, 0) |
| 86 | } |
| 87 | mzeros.Encode(enc, 1) |
| 88 | |
| 89 | mvalues := mValues(nbits) |
| 90 | for _, i := range props { |
| 91 | val := uint(bit.ZEncode(int64(getProp(i)))) |
| 92 | mvalues.Encode(enc, val) |
| 93 | } |
no test coverage detected