mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-26 10:37:04 -06:00
Due to limitations in Go we cannot create a Def for a Map or Set that has a key that is a Map, Set or a List. This is because the key if a Go map needs to be a comparable and maps and slices are not comparable.
125 lines
2.6 KiB
Cheetah
125 lines
2.6 KiB
Cheetah
// {{.Name}}
|
|
|
|
type {{.Name}} struct {
|
|
s types.Set
|
|
}
|
|
|
|
func New{{.Name}}() {{.Name}} {
|
|
return {{.Name}}{types.NewSet()}
|
|
}
|
|
|
|
{{if .CanUseDef}}
|
|
type {{.Name}}Def map[{{defType .ElemType}}]bool
|
|
|
|
func (def {{.Name}}Def) New() {{.Name}} {
|
|
l := make([]types.Value, len(def))
|
|
i := 0
|
|
for d, _ := range def {
|
|
l[i] = {{defToValue "d" .ElemType}}
|
|
i++
|
|
}
|
|
return {{.Name}}{types.NewSet(l...)}
|
|
}
|
|
|
|
func (s {{.Name}}) Def() {{.Name}}Def {
|
|
def := make(map[{{defType .ElemType}}]bool, s.Len())
|
|
s.s.Iter(func(v types.Value) bool {
|
|
def[{{valueToDef "v" .ElemType}}] = true
|
|
return false
|
|
})
|
|
return def
|
|
}
|
|
{{end}}
|
|
|
|
func {{.Name}}FromVal(p types.Value) {{.Name}} {
|
|
return {{.Name}}{p.(types.Set)}
|
|
}
|
|
|
|
func (s {{.Name}}) NomsValue() types.Value {
|
|
return s.s
|
|
}
|
|
|
|
func (s {{.Name}}) Equals(p {{.Name}}) bool {
|
|
return s.s.Equals(p.s)
|
|
}
|
|
|
|
func (s {{.Name}}) Ref() ref.Ref {
|
|
return s.s.Ref()
|
|
}
|
|
|
|
func (s {{.Name}}) Empty() bool {
|
|
return s.s.Empty()
|
|
}
|
|
|
|
func (s {{.Name}}) Len() uint64 {
|
|
return s.s.Len()
|
|
}
|
|
|
|
func (s {{.Name}}) Has(p {{userType .ElemType}}) bool {
|
|
return s.s.Has({{userToValue "p" .ElemType}})
|
|
}
|
|
|
|
type {{.Name}}IterCallback func(p {{userType .ElemType}}) (stop bool)
|
|
|
|
func (s {{.Name}}) Iter(cb {{.Name}}IterCallback) {
|
|
s.s.Iter(func(v types.Value) bool {
|
|
return cb({{valueToUser "v" .ElemType}})
|
|
})
|
|
}
|
|
|
|
type {{.Name}}IterAllCallback func(p {{userType .ElemType}})
|
|
|
|
func (s {{.Name}}) IterAll(cb {{.Name}}IterAllCallback) {
|
|
s.s.IterAll(func(v types.Value) {
|
|
cb({{valueToUser "v" .ElemType}})
|
|
})
|
|
}
|
|
|
|
type {{.Name}}FilterCallback func(p {{userType .ElemType}}) (keep bool)
|
|
|
|
func (s {{.Name}}) Filter(cb {{.Name}}FilterCallback) {{.Name}} {
|
|
ns := New{{.Name}}()
|
|
s.IterAll(func(v {{userType .ElemType}}) {
|
|
if cb(v) {
|
|
ns = ns.Insert(v)
|
|
}
|
|
})
|
|
return ns
|
|
}
|
|
|
|
func (s {{.Name}}) Insert(p ...{{userType .ElemType}}) {{.Name}} {
|
|
return {{.Name}}{s.s.Insert(s.fromElemSlice(p)...)}
|
|
}
|
|
|
|
func (s {{.Name}}) Remove(p ...{{userType .ElemType}}) {{.Name}} {
|
|
return {{.Name}}{s.s.Remove(s.fromElemSlice(p)...)}
|
|
}
|
|
|
|
func (s {{.Name}}) Union(others ...{{.Name}}) {{.Name}} {
|
|
return {{.Name}}{s.s.Union(s.fromStructSlice(others)...)}
|
|
}
|
|
|
|
func (s {{.Name}}) Subtract(others ...{{.Name}}) {{.Name}} {
|
|
return {{.Name}}{s.s.Subtract(s.fromStructSlice(others)...)}
|
|
}
|
|
|
|
func (s {{.Name}}) Any() {{userType .ElemType}} {
|
|
return {{valueToUser "s.s.Any()" .ElemType}}
|
|
}
|
|
|
|
func (s {{.Name}}) fromStructSlice(p []{{.Name}}) []types.Set {
|
|
r := make([]types.Set, len(p))
|
|
for i, v := range p {
|
|
r[i] = v.s
|
|
}
|
|
return r
|
|
}
|
|
|
|
func (s {{.Name}}) fromElemSlice(p []{{userType .ElemType}}) []types.Value {
|
|
r := make([]types.Value, len(p))
|
|
for i, v := range p {
|
|
r[i] = {{userToValue "v" .ElemType}}
|
|
}
|
|
return r
|
|
}
|