MCPcopy Create free account
hub / github.com/egonelbre/exp / Encode

Method Encode

physicscompress2/physics/encoding.go:36–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34var totalbits = 0
35
36func (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 := &current[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 := &current[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 }

Callers 1

mainFunction · 0.95

Calls 14

HistoricMethod · 0.95
BaselineMethod · 0.95
CurrentMethod · 0.95
CloseMethod · 0.95
BytesMethod · 0.95
NewEncoderFunction · 0.92
ZEncodeFunction · 0.92
ScanRightFunction · 0.92
IndexPropsFunction · 0.85
PropsFunction · 0.85
mZerosFunction · 0.70
SortByZFunction · 0.70

Tested by

no test coverage detected