package dstream import ( "fmt" "time" ) func (sd *segmentedData) GetPos(j int) interface{} { var x interface{} var stash bool if ilen(sd.stash[j]) > 0 { x = sd.stash[j] stash = true } else { x = sd.bdata[j] } switch x := x.(type) { {{- range . }} case []{{ .Type }}: pos := sd.pos if stash { pos = len(x) } return x[0:pos] {{- end }} default: msg := fmt.Sprintf("Segment: unknown type %T\n", x) panic(msg) } } // fixstash appends the matching initial segment of bdata to the // end of the stash func (sd *segmentedData) fixstash() bool { pos, fd := sd.findSegmentStash() if pos == 0 { return true } for j := 0; j= pos { break } if x[i] != x[i-1] { pos = i break } } {{- end }} case nil: return -1 default: msg := fmt.Sprintf("Segment: unknown type %T\n", x) panic(msg) } } return pos } // findSegmentStash finds the first segment boundary in bdata, viewing bstash // as a continuation of stash. func (sd *segmentedData) findSegmentStash() (int, bool) { pos := -1 var m int for _, j := range sd.vpos { x := sd.bdata[j] switch x := x.(type) { {{- range . }} case []{{ .Type }}: m = len(x) y := sd.stash[j].([]{{ .Type }}) v := y[len(y) - 1] for i := 0; i < len(x); i++ { if pos != -1 && i >= pos { break } if x[i] != v { pos = i break } } {{- end }} default: msg := fmt.Sprintf("Segment: unknown type %T", x) panic(msg) } } if pos != -1 { return pos, true } else { return m, false } }