mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-31 03:18:43 -06:00
147 lines
4.1 KiB
Cheetah
147 lines
4.1 KiB
Cheetah
{{$typesPackage := .TypesPackage}}
|
|
|
|
// {{.Name}}
|
|
|
|
type {{.Name}} struct {
|
|
l {{$typesPackage}}List
|
|
cs chunks.ChunkStore
|
|
ref *ref.Ref
|
|
}
|
|
|
|
func New{{.Name}}(cs chunks.ChunkStore) {{.Name}} {
|
|
return {{.Name}}{ {{$typesPackage}}NewTypedList(cs, __typeFor{{.Name}}), cs, &ref.Ref{}}
|
|
}
|
|
|
|
{{if .CanUseDef}}
|
|
type {{.Name}}Def []{{defType .ElemType}}
|
|
|
|
func (def {{.Name}}Def) New(cs chunks.ChunkStore) {{.Name}} {
|
|
l := make([]{{$typesPackage}}Value, len(def))
|
|
for i, d := range def {
|
|
l[i] = {{defToValue "d" .ElemType }}
|
|
}
|
|
return {{.Name}}{ {{$typesPackage}}NewTypedList(cs, __typeFor{{.Name}}, l...), cs, &ref.Ref{}}
|
|
}
|
|
|
|
func (l {{.Name}}) Def() {{.Name}}Def {
|
|
d := make([]{{defType .ElemType}}, l.Len())
|
|
for i := uint64(0); i < l.Len(); i++ {
|
|
d[i] = {{valueToDef "l.l.Get(i)" .ElemType }}
|
|
}
|
|
return d
|
|
}
|
|
{{end}}
|
|
|
|
func (l {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
|
|
return other != nil && __typeFor{{.Name}}.Equals(other.Type()) && l.Ref() == other.Ref()
|
|
}
|
|
|
|
func (l {{.Name}}) Ref() ref.Ref {
|
|
return {{$typesPackage}}EnsureRef(l.ref, l)
|
|
}
|
|
|
|
func (l {{.Name}}) Chunks() (chunks []ref.Ref) {
|
|
chunks = append(chunks, l.Type().Chunks()...)
|
|
chunks = append(chunks, l.l.Chunks()...)
|
|
return
|
|
}
|
|
|
|
func (l {{.Name}}) ChildValues() []{{$typesPackage}}Value {
|
|
return append([]{{$typesPackage}}Value{}, l.l.ChildValues()...)
|
|
}
|
|
|
|
// A Noms Value that describes {{.Name}}.
|
|
var __typeFor{{.Name}} {{$typesPackage}}Type
|
|
|
|
func (m {{.Name}}) Type() {{$typesPackage}}Type {
|
|
return __typeFor{{.Name}}
|
|
}
|
|
|
|
func init() {
|
|
__typeFor{{.Name}} = {{toTypesType .Type .FileID .PackageName}}
|
|
{{$typesPackage}}RegisterValue(__typeFor{{.Name}}, builderFor{{.Name}}, readerFor{{.Name}})
|
|
}
|
|
|
|
func builderFor{{.Name}}(cs chunks.ChunkStore, v {{$typesPackage}}Value) {{$typesPackage}}Value {
|
|
return {{.Name}}{v.({{$typesPackage}}List), cs, &ref.Ref{}}
|
|
}
|
|
|
|
func readerFor{{.Name}}(v {{$typesPackage}}Value) {{$typesPackage}}Value {
|
|
return v.({{.Name}}).l
|
|
}
|
|
|
|
func (l {{.Name}}) Len() uint64 {
|
|
return l.l.Len()
|
|
}
|
|
|
|
func (l {{.Name}}) Empty() bool {
|
|
return l.Len() == uint64(0)
|
|
}
|
|
|
|
func (l {{.Name}}) Get(i uint64) {{userType .ElemType}} {
|
|
return {{valueToUser "l.l.Get(i)" .ElemType}}
|
|
}
|
|
|
|
func (l {{.Name}}) Slice(idx uint64, end uint64) {{.Name}} {
|
|
return {{.Name}}{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
|
|
}
|
|
|
|
func (l {{.Name}}) Set(i uint64, val {{userType .ElemType}}) {{.Name}} {
|
|
return {{.Name}}{l.l.Set(i, {{userToValue "val" .ElemType}}), l.cs, &ref.Ref{}}
|
|
}
|
|
|
|
func (l {{.Name}}) Append(v ...{{userType .ElemType}}) {{.Name}} {
|
|
return {{.Name}}{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
|
|
}
|
|
|
|
func (l {{.Name}}) Insert(idx uint64, v ...{{userType .ElemType}}) {{.Name}} {
|
|
return {{.Name}}{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
|
|
}
|
|
|
|
func (l {{.Name}}) Remove(idx uint64, end uint64) {{.Name}} {
|
|
return {{.Name}}{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
|
|
}
|
|
|
|
func (l {{.Name}}) RemoveAt(idx uint64) {{.Name}} {
|
|
return {{.Name}}{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
|
|
}
|
|
|
|
func (l {{.Name}}) fromElemSlice(p []{{userType .ElemType}}) []{{$typesPackage}}Value {
|
|
r := make([]{{$typesPackage}}Value, len(p))
|
|
for i, v := range p {
|
|
r[i] = {{userToValue "v" .ElemType}}
|
|
}
|
|
return r
|
|
}
|
|
|
|
type {{.Name}}IterCallback func(v {{userType .ElemType}}, i uint64) (stop bool)
|
|
|
|
func (l {{.Name}}) Iter(cb {{.Name}}IterCallback) {
|
|
l.l.Iter(func(v {{$typesPackage}}Value, i uint64) bool {
|
|
return cb({{valueToUser "v" .ElemType}}, i)
|
|
})
|
|
}
|
|
|
|
type {{.Name}}IterAllCallback func(v {{userType .ElemType}}, i uint64)
|
|
|
|
func (l {{.Name}}) IterAll(cb {{.Name}}IterAllCallback) {
|
|
l.l.IterAll(func(v {{$typesPackage}}Value, i uint64) {
|
|
cb({{valueToUser "v" .ElemType}}, i)
|
|
})
|
|
}
|
|
|
|
func (l {{.Name}}) IterAllP(concurrency int, cb {{.Name}}IterAllCallback) {
|
|
l.l.IterAllP(concurrency, func(v {{$typesPackage}}Value, i uint64) {
|
|
cb({{valueToUser "v" .ElemType}}, i)
|
|
})
|
|
}
|
|
|
|
type {{.Name}}FilterCallback func(v {{userType .ElemType}}, i uint64) (keep bool)
|
|
|
|
func (l {{.Name}}) Filter(cb {{.Name}}FilterCallback) {{.Name}} {
|
|
out := l.l.Filter(func(v {{$typesPackage}}Value, i uint64) bool {
|
|
return cb({{valueToUser "v" .ElemType}}, i)
|
|
})
|
|
return {{.Name}}{out, l.cs, &ref.Ref{}}
|
|
}
|