Key the survey by a pin set's rows spelled as a string

This commit is contained in:
2026-09-29 11:06:57 +02:00
committed by Lillem4n
parent 79e63829c4
commit 4772fa7df3
3 changed files with 26 additions and 47 deletions
+13
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"maps"
"sort"
"strings"
)
type tablePin struct {
@@ -85,6 +86,18 @@ func (p *pinSet) each(fn func(t *table, r int)) {
}
}
// key spells the pinned rows, so two sets pinning the same rows share one.
func (p *pinSet) key() string {
var pins []tablePin
p.each(func(t *table, r int) { pins = append(pins, tablePin{t, r}) })
sort.Slice(pins, func(i, j int) bool { return pins[i].t.path < pins[j].t.path })
var b strings.Builder
for _, q := range pins {
fmt.Fprintf(&b, "%q%d", q.t.path, q.row)
}
return b.String()
}
// clash is the table whose pinned row keeps row r of t out: t itself pinned to another row, or the
// nearest ancestor pinned to a row r is not inside; nil where none does.
func (p *pinSet) clash(t *table, r int) *table {