项目文件夹

文件
wehub-resource-sync c4536f7e05
CI / test (push) Failing after 1s
CI / macOS amd64 (push) Has been cancelled
CI / macOS arm64 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:31 +08:00

63 行
1.3 KiB
Go

package disasm
import "slices"
// LineSet represents a set of needed lines.
type LineSet struct {
list []int
}
// Add adds line to the needed set.
func (rs *LineSet) Add(line int) {
if at, found := slices.BinarySearch(rs.list, line); !found {
rs.list = slices.Insert(rs.list, at, line)
}
}
// Ranges converts line set to line ranges and adds context for extra information.
func (rs *LineSet) Ranges(context int) []LineRange {
if len(rs.list) == 0 {
return nil
}
var all []LineRange
current := LineRange{From: rs.list[0] - context, To: rs.list[0] + context + 1}
if current.From < 1 {
current.From = 1
}
for _, line := range rs.list {
if line-context <= current.To {
current.To = line + context + 1
} else {
all = append(all, current)
current = LineRange{From: line - context, To: line + context + 1}
}
}
all = append(all, current)
return all
}
// RangesZero returns a ranges without expanding by context.
func (rs *LineSet) RangesZero() []LineRange {
if len(rs.list) == 0 {
return nil
}
var all []LineRange
current := LineRange{From: rs.list[0], To: rs.list[0] + 1}
for _, line := range rs.list {
if line <= current.To {
current.To = line + 1
} else {
all = append(all, current)
current = LineRange{From: line, To: line + 1}
}
}
all = append(all, current)
return all
}