Answer architecture round 1: rows.Options checked whole in internal/rows, Owner and ProveStepUp, neutral pin docs, one walk position, tests of internal/rows and Weighted, and a true README list of Fake's failures
This commit is contained in:
+20
-20
@@ -6,19 +6,19 @@ import (
|
||||
"github.com/larvit/fejkdata/internal/invariant"
|
||||
)
|
||||
|
||||
type pin[P any] struct {
|
||||
t *Table[P]
|
||||
type pin[O any] struct {
|
||||
t *Table[O]
|
||||
row int
|
||||
}
|
||||
|
||||
// Pins is the table rows fixed so far.
|
||||
type Pins[P any] struct {
|
||||
inline [8]pin[P] // sized so a render over a country's five-deep geo tree stays off the heap
|
||||
type Pins[O any] struct {
|
||||
inline [8]pin[O] // sized so a render over a country's five-deep geo tree stays off the heap
|
||||
used int
|
||||
spill map[*Table[P]]int
|
||||
spill map[*Table[O]]int
|
||||
}
|
||||
|
||||
func (p *Pins[P]) Pinned(t *Table[P]) (int, bool) {
|
||||
func (p *Pins[O]) Pinned(t *Table[O]) (int, bool) {
|
||||
for _, q := range p.inline[:p.used] {
|
||||
if q.t == t {
|
||||
return q.row, true
|
||||
@@ -28,23 +28,23 @@ func (p *Pins[P]) Pinned(t *Table[P]) (int, bool) {
|
||||
return r, ok
|
||||
}
|
||||
|
||||
// MustRow is the row pinned for t, which the walk reaching a column pinned.
|
||||
func (p *Pins[P]) MustRow(t *Table[P]) int {
|
||||
// MustRow is the row pinned for t, which the caller pinned.
|
||||
func (p *Pins[O]) MustRow(t *Table[O]) int {
|
||||
r, ok := p.Pinned(t)
|
||||
if !ok {
|
||||
panic(invariant.Broken("a column of %s is rendered with no row pinned", t.segment))
|
||||
panic(invariant.Broken("no row of %s is pinned", t.segment))
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (p *Pins[P]) add(t *Table[P], r int) {
|
||||
func (p *Pins[O]) add(t *Table[O], r int) {
|
||||
if p.used < len(p.inline) {
|
||||
p.inline[p.used] = pin[P]{t, r}
|
||||
p.inline[p.used] = pin[O]{t, r}
|
||||
p.used++
|
||||
return
|
||||
}
|
||||
if p.spill == nil {
|
||||
p.spill = map[*Table[P]]int{}
|
||||
p.spill = map[*Table[O]]int{}
|
||||
}
|
||||
p.spill[t] = r
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (p *Pins[P]) add(t *Table[P], r int) {
|
||||
// pin pins row r of t, and the rows of t's ancestors it links to. It checks nothing, so r must
|
||||
// agree with the row p pins of nearestPinned(t): ask clash first, as PinRow does, or draw r inside
|
||||
// it, as DrawIn does.
|
||||
func (p *Pins[P]) pin(t *Table[P], r int) {
|
||||
func (p *Pins[O]) pin(t *Table[O], r int) {
|
||||
for stop := p.nearestPinned(t); t != stop; t = t.parent {
|
||||
p.add(t, r)
|
||||
if t.parent != stop {
|
||||
@@ -63,7 +63,7 @@ func (p *Pins[P]) pin(t *Table[P], r int) {
|
||||
|
||||
// nearestPinned is the first of t and its ancestors p pins, where pinning a row of t stops; nil
|
||||
// where none is.
|
||||
func (p *Pins[P]) nearestPinned(t *Table[P]) *Table[P] {
|
||||
func (p *Pins[O]) nearestPinned(t *Table[O]) *Table[O] {
|
||||
for ; t != nil; t = t.parent {
|
||||
if _, ok := p.Pinned(t); ok {
|
||||
return t
|
||||
@@ -74,7 +74,7 @@ func (p *Pins[P]) nearestPinned(t *Table[P]) *Table[P] {
|
||||
|
||||
// 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 *Pins[P]) clash(t *Table[P], r int) *Table[P] {
|
||||
func (p *Pins[O]) clash(t *Table[O], r int) *Table[O] {
|
||||
if pr, ok := p.Pinned(t); ok && pr != r {
|
||||
return t
|
||||
}
|
||||
@@ -87,7 +87,7 @@ func (p *Pins[P]) clash(t *Table[P], r int) *Table[P] {
|
||||
}
|
||||
|
||||
// PinRow pins row r of t where it agrees with the rows pinned before it.
|
||||
func (p *Pins[P]) PinRow(t *Table[P], r int) error {
|
||||
func (p *Pins[O]) PinRow(t *Table[O], r int) error {
|
||||
switch a := p.clash(t, r); {
|
||||
case a == t:
|
||||
pr, _ := p.Pinned(t)
|
||||
@@ -101,7 +101,7 @@ func (p *Pins[P]) PinRow(t *Table[P], r int) error {
|
||||
}
|
||||
|
||||
// Select pins the row of t that sel names, and returns it.
|
||||
func (p *Pins[P]) Select(t *Table[P], sel string) (int, error) {
|
||||
func (p *Pins[O]) Select(t *Table[O], sel string) (int, error) {
|
||||
r, err := t.find(sel, p)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -110,7 +110,7 @@ func (p *Pins[P]) Select(t *Table[P], sel string) (int, error) {
|
||||
}
|
||||
|
||||
// inside keeps the rows of t that sit inside every pinned ancestor.
|
||||
func (p *Pins[P]) inside(t *Table[P], rows []int) []int {
|
||||
func (p *Pins[O]) inside(t *Table[O], rows []int) []int {
|
||||
for a := t.parent; a != nil; a = a.parent {
|
||||
pa, ok := p.Pinned(a)
|
||||
if !ok {
|
||||
@@ -128,8 +128,8 @@ func (p *Pins[P]) inside(t *Table[P], rows []int) []int {
|
||||
}
|
||||
|
||||
// Above is a pin set holding the rows p pins of t and its ancestors, and none below them.
|
||||
func (p *Pins[P]) Above(t *Table[P]) *Pins[P] {
|
||||
q := new(Pins[P])
|
||||
func (p *Pins[O]) Above(t *Table[O]) *Pins[O] {
|
||||
q := new(Pins[O])
|
||||
for ; t != nil; t = t.parent {
|
||||
if r, ok := p.Pinned(t); ok {
|
||||
q.add(t, r)
|
||||
|
||||
Reference in New Issue
Block a user