|
|
@ -1,14 +1,16 @@
|
|
|
|
package ent
|
|
|
|
package ent
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/jordanorelli/hyperstone/bit"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// a fieldpath is a list of integers that is used to walk the type hierarchy to
|
|
|
|
// a fieldpath is a list of integers that is used to walk the type hierarchy to
|
|
|
|
// identify a given field on a given type.
|
|
|
|
// identify a given field on a given type.
|
|
|
|
type fieldPath struct {
|
|
|
|
type fieldPath struct {
|
|
|
|
|
|
|
|
// slice of values, to be reused over and over
|
|
|
|
vals []int
|
|
|
|
vals []int
|
|
|
|
|
|
|
|
// index of the last valid value. e.g., the head of the stack.
|
|
|
|
last int
|
|
|
|
last int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -38,10 +40,20 @@ func (f *fieldPath) replaceAll(fn func(v int) int) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (f *fieldPath) pathString() string {
|
|
|
|
// reads the sequence of id values off of the provided bit reader given the
|
|
|
|
var buf bytes.Buffer
|
|
|
|
// huffman tree of fieldpath ops rooted at the node n
|
|
|
|
for i := 0; i <= f.last; i++ {
|
|
|
|
func (f *fieldPath) read(br bit.Reader, n node) error {
|
|
|
|
fmt.Fprintf(&buf, "/%d", f.vals[i])
|
|
|
|
f.last = 0
|
|
|
|
|
|
|
|
for fn := walk(n, br); fn != nil; fn = walk(n, br) {
|
|
|
|
|
|
|
|
if err := br.Err(); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("unable to read fieldpath: reader error: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fn(f, br)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buf.String()
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the subslice of valid index values that has been read on the fieldpath
|
|
|
|
|
|
|
|
func (f *fieldPath) path() []int {
|
|
|
|
|
|
|
|
return f.vals[:f.last+1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|