mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-26 10:37:04 -06:00
113 lines
2.7 KiB
Cheetah
113 lines
2.7 KiB
Cheetah
// {{.Name}}
|
|
|
|
type {{.Name}} struct {
|
|
m types.Map
|
|
}
|
|
|
|
|
|
func New{{.Name}}() {{.Name}} {
|
|
return {{.Name}}{types.NewMap()}
|
|
}
|
|
|
|
{{if .CanUseDef}}
|
|
type {{.Name}}Def map[{{defType .KeyType}}]{{defType .ValueType}}
|
|
|
|
func (def {{.Name}}Def) New() {{.Name}} {
|
|
kv := make([]types.Value, 0, len(def)*2)
|
|
for k, v := range def {
|
|
kv = append(kv, {{defToValue "k" .KeyType}}, {{defToValue "v" .ValueType}})
|
|
}
|
|
return {{.Name}}{types.NewMap(kv...)}
|
|
}
|
|
|
|
func (m {{.Name}}) Def() {{.Name}}Def {
|
|
def := make(map[{{defType .KeyType}}]{{defType .ValueType}})
|
|
m.m.Iter(func(k, v types.Value) bool {
|
|
def[{{valueToDef "k" .KeyType}}] = {{valueToDef "v" .ValueType}}
|
|
return false
|
|
})
|
|
return def
|
|
}
|
|
{{end}}
|
|
|
|
func {{.Name}}FromVal(p types.Value) {{.Name}} {
|
|
// TODO: Validate here
|
|
return {{.Name}}{p.(types.Map)}
|
|
}
|
|
|
|
func (m {{.Name}}) NomsValue() types.Value {
|
|
return m.m
|
|
}
|
|
|
|
func (m {{.Name}}) Equals(other types.Value) bool {
|
|
if other, ok := other.({{.Name}}); ok {
|
|
return m.m.Equals(other.m)
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (m {{.Name}}) Ref() ref.Ref {
|
|
return m.m.Ref()
|
|
}
|
|
|
|
func (m {{.Name}}) Chunks() []types.Future {
|
|
return m.m.Chunks()
|
|
}
|
|
|
|
{{template "type_ref.tmpl" .}}
|
|
|
|
func (m {{.Name}}) Empty() bool {
|
|
return m.m.Empty()
|
|
}
|
|
|
|
func (m {{.Name}}) Len() uint64 {
|
|
return m.m.Len()
|
|
}
|
|
|
|
func (m {{.Name}}) Has(p {{userType .KeyType}}) bool {
|
|
return m.m.Has({{userToValue "p" .KeyType}})
|
|
}
|
|
|
|
func (m {{.Name}}) Get(p {{userType .KeyType}}) {{userType .ValueType}} {
|
|
return {{valueToUser (printf "m.m.Get(%s)" (userToValue "p" .KeyType)) .ValueType}}
|
|
}
|
|
|
|
func (m {{.Name}}) Set(k {{userType .KeyType}}, v {{userType .ValueType}}) {{.Name}} {
|
|
return {{.Name}}{m.m.Set({{userToValue "k" .KeyType}}, {{userToValue "v" .ValueType}})}
|
|
}
|
|
|
|
// TODO: Implement SetM?
|
|
|
|
func (m {{.Name}}) Remove(p {{userType .KeyType}}) {{.Name}} {
|
|
return {{.Name}}{m.m.Remove({{userToValue "p" .KeyType}})}
|
|
}
|
|
|
|
type {{.Name}}IterCallback func(k {{userType .KeyType}}, v {{userType .ValueType}}) (stop bool)
|
|
|
|
func (m {{.Name}}) Iter(cb {{.Name}}IterCallback) {
|
|
m.m.Iter(func(k, v types.Value) bool {
|
|
return cb({{valueToUser "k" .KeyType}}, {{valueToUser "v" .ValueType}})
|
|
})
|
|
}
|
|
|
|
type {{.Name}}IterAllCallback func(k {{userType .KeyType}}, v {{userType .ValueType}})
|
|
|
|
func (m {{.Name}}) IterAll(cb {{.Name}}IterAllCallback) {
|
|
m.m.IterAll(func(k, v types.Value) {
|
|
cb({{valueToUser "k" .KeyType}}, {{valueToUser "v" .ValueType}})
|
|
})
|
|
}
|
|
|
|
|
|
type {{.Name}}FilterCallback func(k {{userType .KeyType}}, v {{userType .ValueType}}) (keep bool)
|
|
|
|
func (m {{.Name}}) Filter(cb {{.Name}}FilterCallback) {{.Name}} {
|
|
nm := New{{.Name}}()
|
|
m.IterAll(func(k {{userType .KeyType}}, v {{userType .ValueType}}) {
|
|
if cb(k, v) {
|
|
nm = nm.Set(k, v)
|
|
}
|
|
})
|
|
return nm
|
|
}
|