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

Method Encode

physicscompress/physics/encoding.go:23–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21var totalbits = 0
22
23func (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 := &current[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 := &current[i]
44 mzeros.Encode(enc, uint(cube.Interacting^1))
45 }
46
47 for _, i := range items {
48 cube, base := &current[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))))

Callers 1

mainFunction · 0.95

Calls 15

HistoricMethod · 0.95
BaselineMethod · 0.95
CurrentMethod · 0.95
CloseMethod · 0.95
BytesMethod · 0.95
NewEncoderFunction · 0.92
ZEncodeFunction · 0.92
ScanRightFunction · 0.92
Index6Function · 0.85
Delta6Function · 0.85
Extra6Function · 0.85
mZerosFunction · 0.70

Tested by

no test coverage detected