MCPcopy Create free account
hub / github.com/brimdata/super / addPath

Method addPath

runtime/sam/expr/function/unflatten.go:136–160  ·  view source on GitHub ↗
(c *recordCache, p []string)

Source from the content-addressed store, hash-verified

134}
135
136func (r *record) addPath(c *recordCache, p []string) (removed int) {
137 if len(p) == 0 {
138 return 0
139 }
140 at := len(r.fields) - 1
141 if len(r.fields) == 0 || r.fields[at].Name != p[0] {
142 r.fields = append(r.fields, super.NewField(p[0], nil))
143 var rec *record
144 if len(p) > 1 {
145 rec = c.new()
146 }
147 r.records = append(r.records, rec)
148 } else if len(p) == 1 || r.records[at] == nil {
149 // If this isn't a new field and we're either at a leaf or the
150 // previously value was a leaf, we're stacking on a previously created
151 // record and need to signal that values have been removed.
152 removed = r.records[at].countLeaves()
153 if len(p) > 1 {
154 r.records[at] = c.new()
155 } else {
156 r.records[at] = nil
157 }
158 }
159 return removed + r.records[len(r.records)-1].addPath(c, p[1:])
160}
161
162func (r *record) countLeaves() int {
163 if r == nil {

Callers 1

CallMethod · 0.80

Calls 3

NewFieldFunction · 0.92
newMethod · 0.80
countLeavesMethod · 0.80

Tested by

no test coverage detected