是否可以让memoryByteRanges
继承TotalLength
的方法Len
,Swap
,Less
,byteRanges
,而不必重新定义功能?
type byteRange struct {
start int
end int
}
type byteRanges []*byteRange
func (brs byteRanges) Len() int {
return len(brs)
}
func (brs byteRanges) Swap(i, j int) {
brs[i], brs[j] = brs[j], brs[i]
}
func (brs byteRanges) Less(i, j int) bool {
return brs[i].start < brs[j].start
}
func (brs byteRanges) TotalLength(i, j int) bool {
l := 0
for _, br := range brs {
l = l + br.end - br.start
}
return l
}
type memoryByteRange struct {
byteRange
data []byte
}
type memoryByteRanges []*memoryByteRange