{{$typesPackage := .TypesPackage}} // {{.Name}} type {{.Name}} struct { m {{$typesPackage}}Map cs chunks.ChunkStore ref *ref.Ref } func New{{.Name}}(cs chunks.ChunkStore) {{.Name}} { return {{.Name}}{ {{$typesPackage}}NewTypedMap(cs, __typeFor{{.Name}}), cs, &ref.Ref{}} } {{if .CanUseDef}} type {{.Name}}Def map[{{defType .KeyType}}]{{defType .ValueType}} func (def {{.Name}}Def) New(cs chunks.ChunkStore) {{.Name}} { kv := make([]{{$typesPackage}}Value, 0, len(def)*2) for k, v := range def { kv = append(kv, {{defToValue "k" .KeyType}}, {{defToValue "v" .ValueType}}) } return {{.Name}}{ {{$typesPackage}}NewTypedMap(cs, __typeFor{{.Name}}, kv...), cs, &ref.Ref{}} } func (m {{.Name}}) Def() {{.Name}}Def { def := make(map[{{defType .KeyType}}]{{defType .ValueType}}) m.m.Iter(func(k, v {{$typesPackage}}Value) bool { def[{{valueToDef "k" .KeyType}}] = {{valueToDef "v" .ValueType}} return false }) return def } {{end}} func (m {{.Name}}) Equals(other {{$typesPackage}}Value) bool { return other != nil && __typeFor{{.Name}}.Equals(other.Type()) && m.Ref() == other.Ref() } func (m {{.Name}}) Ref() ref.Ref { return {{$typesPackage}}EnsureRef(m.ref, m) } func (m {{.Name}}) Chunks() (chunks []ref.Ref) { chunks = append(chunks, m.Type().Chunks()...) chunks = append(chunks, m.m.Chunks()...) return } func (m {{.Name}}) ChildValues() []{{$typesPackage}}Value { return append([]{{$typesPackage}}Value{}, m.m.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}}Map), cs, &ref.Ref{}} } func readerFor{{.Name}}(v {{$typesPackage}}Value) {{$typesPackage}}Value { return v.({{.Name}}).m } 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}}) MaybeGet(p {{userType .KeyType}}) ({{userType .ValueType}}, bool) { v, ok := m.m.MaybeGet({{userToValue "p" .KeyType}}) if !ok { return {{userZero "m.cs" .ValueType}}, false } return {{valueToUser "v" .ValueType}}, ok } func (m {{.Name}}) Set(k {{userType .KeyType}}, v {{userType .ValueType}}) {{.Name}} { return {{.Name}}{m.m.Set({{userToValue "k" .KeyType}}, {{userToValue "v" .ValueType}}), m.cs, &ref.Ref{}} } // TODO: Implement SetM? func (m {{.Name}}) Remove(p {{userType .KeyType}}) {{.Name}} { return {{.Name}}{m.m.Remove({{userToValue "p" .KeyType}}), m.cs, &ref.Ref{}} } 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 {{$typesPackage}}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 {{$typesPackage}}Value) { cb({{valueToUser "k" .KeyType}}, {{valueToUser "v" .ValueType}}) }) } func (m {{.Name}}) IterAllP(concurrency int, cb {{.Name}}IterAllCallback) { m.m.IterAllP(concurrency, func(k, v {{$typesPackage}}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}} { out := m.m.Filter(func(k, v {{$typesPackage}}Value) bool { return cb({{valueToUser "k" .KeyType}}, {{valueToUser "v" .ValueType}}) }) return {{.Name}}{out, m.cs, &ref.Ref{}} }