This file is indexed.

/usr/share/gocode/src/github.com/influxdata/influxdb/tsdb/engine/tsm1/encoding.gen.go.tmpl is in golang-github-influxdb-influxdb-dev 1.1.1+dfsg1-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package tsm1

import (
	"fmt"
	"sort"
)

{{range .}}

// {{.Name}}Values represents a slice of {{.Name}} values.
type {{.Name}}Values []{{.Name}}Value

func (a {{.Name}}Values) MinTime() int64 {
	return a[0].UnixNano()
}

func (a {{.Name}}Values) MaxTime() int64 {
	return a[len(a)-1].UnixNano()
}

func (a {{.Name}}Values) Size() int {
	sz := 0
	for _, v := range a {
		sz += v.Size()
	}
	return sz
}

func (a {{.Name}}Values) ordered() bool {
	if len(a) <= 1 {
		return true
	}
	for i := 1; i < len(a); i++ {
		if av, ab := a[i-1].UnixNano(), a[i].UnixNano(); av >= ab {
			return false
		}
	}
	return true
}

func (a {{.Name}}Values) assertOrdered() {
	if len(a) <= 1 {
		return
	}
	for i := 1; i < len(a); i++ {
		if av, ab := a[i-1].UnixNano(), a[i].UnixNano(); av >= ab {
			panic(fmt.Sprintf("not ordered: %d %d >= %d", i, av, ab))
		}
	}
}


// Deduplicate returns a new slice with any values that have the same timestamp removed.
// The Value that appears last in the slice is the one that is kept.
func (a {{.Name}}Values) Deduplicate() {{.Name}}Values {
	m := make(map[int64]{{.Name}}Value)
	for _, val := range a {
		m[val.UnixNano()] = val
	}

	other := make({{.Name}}Values, 0, len(m))
	for _, val := range m {
		other = append(other, val)
	}

	sort.Sort(other)
	return other
}

//  Exclude returns the subset of values not in [min, max]
func (a {{.Name}}Values) Exclude(min, max int64) {{.Name}}Values {
	var i int
	for j := 0; j < len(a); j++ {
		if a[j].UnixNano() >= min && a[j].UnixNano() <= max {
			continue
		}

		a[i] = a[j]
		i++
	}
	return a[:i]
}

// Include returns the subset values between min and max inclusive.
func (a {{.Name}}Values) Include(min, max int64) {{.Name}}Values {
	var i int
	for j := 0; j < len(a); j++ {
		if a[j].UnixNano() < min || a[j].UnixNano() > max {
			continue
		}

		a[i] = a[j]
		i++
	}
	return a[:i]
}

// Merge overlays b to top of a.  If two values conflict with
// the same timestamp, b is used.  Both a and b must be sorted
// in ascending order.
func (a {{.Name}}Values) Merge(b {{.Name}}Values) {{.Name}}Values {
	if len(a) == 0 {
		return b
	}

	if len(b) == 0 {
		return a
	}

	// Normally, both a and b should not contain duplicates.  Due to a bug in older versions, it's
	// possible stored blocks might contain duplicate values.  Remove them if they exists before
	// merging.
	if !a.ordered() {
		a = a.Deduplicate()
	}

	if !b.ordered() {
		b = b.Deduplicate()
	}

	if a[len(a)-1].UnixNano() < b[0].UnixNano() {
		return append(a, b...)
	}

	if b[len(b)-1].UnixNano() < a[0].UnixNano() {
		return append(b, a...)
	}

	for i := 0; i < len(a) && len(b) > 0; i++ {
		av, bv := a[i].UnixNano(), b[0].UnixNano()
		// Value in a is greater than B, we need to merge
		if av > bv {
			// Save value in a
			temp := a[i]

			// Overwrite a with b
			a[i] = b[0]

			// Slide all values of b down 1
			copy(b, b[1:])
			b = b[:len(b)-1]

			var k int
			if len(b) > 0 && av > b[len(b)-1].UnixNano() {
				// Fast path where a is after b, we skip the search
				k = len(b)
			} else {
				// See where value we save from a should be inserted in b to keep b sorted
				k = sort.Search(len(b), func(i int) bool { return b[i].UnixNano() >= temp.UnixNano() })
			}

			if k == len(b) {
				// Last position?
				b = append(b, temp)
			} else if b[k].UnixNano() != temp.UnixNano() {
				// Save the last element, since it will get overwritten
				last := b[len(b)-1]
				// Somewhere in the middle of b, insert it only if it's not a duplicate
				copy(b[k+1:], b[k:])
				// Add the last vale to the end
				b = append(b, last)
				b[k] = temp
			}
		} else if av == bv {
			// Value in a an b are the same, use b
			a[i] = b[0]
			b = b[1:]
		}
	}

	if len(b) > 0 {
		return append(a, b...)
	}
	return a
}

// Sort methods
func (a {{.Name}}Values) Len() int           { return len(a) }
func (a {{.Name}}Values) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a {{.Name}}Values) Less(i, j int) bool { return a[i].UnixNano() < a[j].UnixNano() }


{{ end }}