Key the survey by a pin set's rows spelled as a string
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user