Skip to content

Commit b027956

Browse files
committed
tree: use math.MaxInt for the malformed-span sentinel (review)
Replaces the 1<<30 magic sentinel in tocEntry.span with math.MaxInt so the intent is explicit and it doesn't depend on int width. Per Sourcery review on #39.
1 parent c011453 commit b027956

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

pkg/tree/heading_path.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package tree
22

3-
import "strings"
3+
import (
4+
"math"
5+
"strings"
6+
)
47

58
// BuildHeadingPaths reconciles the parser's section tree with the
69
// LLM-built TOC tree into one canonical lookup: section ID → logical
@@ -86,11 +89,12 @@ type tocEntry struct {
8689
path []string
8790
}
8891

89-
// span is the inclusive page count the entry covers. A zero/negative
90-
// span (malformed node that survived resolution) sorts last.
92+
// span is the inclusive page count the entry covers. A malformed node
93+
// (end < start) that survived resolution reports the maximum span so it
94+
// sorts last in specificity comparisons, regardless of int width.
9195
func (e tocEntry) span() int {
9296
if e.end < e.start {
93-
return 1 << 30
97+
return math.MaxInt
9498
}
9599
return e.end - e.start + 1
96100
}

0 commit comments

Comments
 (0)