From 9a3e73779dde870c29f2ca16f197b43960b96c64 Mon Sep 17 00:00:00 2001 From: Benjamin Kalman Date: Fri, 11 Dec 2015 11:29:09 -0800 Subject: [PATCH] Make types.Ref implement the OrderedValue interface. This fixes the bug where compoundSets/Maps of refs are ordered by their type.Ref's Ref, rather than their type.Ref's TargetRef. --- clients/common/incident.noms.go | 6 +- clients/common/quad_tree.noms.go | 12 +- clients/crunchbase/importer/importer.noms.go | 12 +- clients/crunchbase/importer/sha1_9fb26a6.go | 6 +- clients/crunchbase/index/index.noms.go | 12 +- clients/crunchbase/index/sha1_2a87e00.go | 12 +- clients/crunchbase/index/sha1_9fb26a6.go | 6 +- clients/flickr/types.noms.go | 18 +- clients/picasa/picasa.noms.go | 18 +- clients/pitchmap/index/types.noms.go | 12 +- clients/tagdex/types.noms.go | 6 +- clients/util/types.noms.go | 6 +- datas/types.noms.go | 6 +- nomdl/codegen/ref.tmpl | 6 +- nomdl/codegen/test/gen/ref.noms.go | 18 +- nomdl/pkg/gen/generate_parser.sh | 2 +- types/compound_map_test.go | 185 +++++++++---------- types/compound_set_test.go | 158 ++++++++-------- types/package_set_of_ref.go | 4 + types/ref.go | 4 + types/type.go | 8 +- types/type_desc.go | 9 - types/type_test.go | 2 +- 23 files changed, 314 insertions(+), 214 deletions(-) diff --git a/clients/common/incident.noms.go b/clients/common/incident.noms.go index a3c73ae31d..65288d792f 100644 --- a/clients/common/incident.noms.go +++ b/clients/common/incident.noms.go @@ -496,10 +496,14 @@ func (r RefOfIncident) ChildValues() []types.Value { // A Noms Value that describes RefOfIncident. var __typeForRefOfIncident types.Type -func (m RefOfIncident) Type() types.Type { +func (r RefOfIncident) Type() types.Type { return __typeForRefOfIncident } +func (r RefOfIncident) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfIncident = types.MakeCompoundType(types.RefKind, types.MakeType(__commonPackageInFile_incident_CachedRef, 0)) types.RegisterRef(__typeForRefOfIncident, builderForRefOfIncident) diff --git a/clients/common/quad_tree.noms.go b/clients/common/quad_tree.noms.go index 6b1db94787..ffa52786a4 100644 --- a/clients/common/quad_tree.noms.go +++ b/clients/common/quad_tree.noms.go @@ -570,10 +570,14 @@ func (r RefOfValue) ChildValues() []types.Value { // A Noms Value that describes RefOfValue. var __typeForRefOfValue types.Type -func (m RefOfValue) Type() types.Type { +func (r RefOfValue) Type() types.Type { return __typeForRefOfValue } +func (r RefOfValue) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfValue = types.MakeCompoundType(types.RefKind, types.MakePrimitiveType(types.ValueKind)) types.RegisterRef(__typeForRefOfValue, builderForRefOfValue) @@ -1181,10 +1185,14 @@ func (r RefOfSQuadTree) ChildValues() []types.Value { // A Noms Value that describes RefOfSQuadTree. var __typeForRefOfSQuadTree types.Type -func (m RefOfSQuadTree) Type() types.Type { +func (r RefOfSQuadTree) Type() types.Type { return __typeForRefOfSQuadTree } +func (r RefOfSQuadTree) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfSQuadTree = types.MakeCompoundType(types.RefKind, types.MakeType(__commonPackageInFile_quad_tree_CachedRef, 2)) types.RegisterRef(__typeForRefOfSQuadTree, builderForRefOfSQuadTree) diff --git a/clients/crunchbase/importer/importer.noms.go b/clients/crunchbase/importer/importer.noms.go index 557de46465..23e7102846 100644 --- a/clients/crunchbase/importer/importer.noms.go +++ b/clients/crunchbase/importer/importer.noms.go @@ -289,10 +289,14 @@ func (r RefOfMapOfStringToRefOfCompany) ChildValues() []types.Value { // A Noms Value that describes RefOfMapOfStringToRefOfCompany. var __typeForRefOfMapOfStringToRefOfCompany types.Type -func (m RefOfMapOfStringToRefOfCompany) Type() types.Type { +func (r RefOfMapOfStringToRefOfCompany) Type() types.Type { return __typeForRefOfMapOfStringToRefOfCompany } +func (r RefOfMapOfStringToRefOfCompany) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfMapOfStringToRefOfCompany = types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.MapKind, types.MakePrimitiveType(types.StringKind), types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-9fb26a609a1d4134935888c9676c79d6ea89acbb"), 0)))) types.RegisterRef(__typeForRefOfMapOfStringToRefOfCompany, builderForRefOfMapOfStringToRefOfCompany) @@ -480,10 +484,14 @@ func (r RefOfCompany) ChildValues() []types.Value { // A Noms Value that describes RefOfCompany. var __typeForRefOfCompany types.Type -func (m RefOfCompany) Type() types.Type { +func (r RefOfCompany) Type() types.Type { return __typeForRefOfCompany } +func (r RefOfCompany) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfCompany = types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-9fb26a609a1d4134935888c9676c79d6ea89acbb"), 0)) types.RegisterRef(__typeForRefOfCompany, builderForRefOfCompany) diff --git a/clients/crunchbase/importer/sha1_9fb26a6.go b/clients/crunchbase/importer/sha1_9fb26a6.go index f34f7df413..96ae98e7d3 100644 --- a/clients/crunchbase/importer/sha1_9fb26a6.go +++ b/clients/crunchbase/importer/sha1_9fb26a6.go @@ -947,10 +947,14 @@ func (r RefOfRound) ChildValues() []types.Value { // A Noms Value that describes RefOfRound. var __typeForRefOfRound types.Type -func (m RefOfRound) Type() types.Type { +func (r RefOfRound) Type() types.Type { return __typeForRefOfRound } +func (r RefOfRound) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfRound = types.MakeCompoundType(types.RefKind, types.MakeType(__mainPackageInFile_sha1_9fb26a6_CachedRef, 1)) types.RegisterRef(__typeForRefOfRound, builderForRefOfRound) diff --git a/clients/crunchbase/index/index.noms.go b/clients/crunchbase/index/index.noms.go index f4378219dd..1c1da91795 100644 --- a/clients/crunchbase/index/index.noms.go +++ b/clients/crunchbase/index/index.noms.go @@ -898,10 +898,14 @@ func (r RefOfKey) ChildValues() []types.Value { // A Noms Value that describes RefOfKey. var __typeForRefOfKey types.Type -func (m RefOfKey) Type() types.Type { +func (r RefOfKey) Type() types.Type { return __typeForRefOfKey } +func (r RefOfKey) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfKey = types.MakeCompoundType(types.RefKind, types.MakeType(__mainPackageInFile_index_CachedRef, 2)) types.RegisterRef(__typeForRefOfKey, builderForRefOfKey) @@ -1105,10 +1109,14 @@ func (r RefOfSetOfRoundRaise) ChildValues() []types.Value { // A Noms Value that describes RefOfSetOfRoundRaise. var __typeForRefOfSetOfRoundRaise types.Type -func (m RefOfSetOfRoundRaise) Type() types.Type { +func (r RefOfSetOfRoundRaise) Type() types.Type { return __typeForRefOfSetOfRoundRaise } +func (r RefOfSetOfRoundRaise) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfSetOfRoundRaise = types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.SetKind, types.MakeType(__mainPackageInFile_index_CachedRef, 4))) types.RegisterRef(__typeForRefOfSetOfRoundRaise, builderForRefOfSetOfRoundRaise) diff --git a/clients/crunchbase/index/sha1_2a87e00.go b/clients/crunchbase/index/sha1_2a87e00.go index a1fd5edcf2..ea9bbac32f 100644 --- a/clients/crunchbase/index/sha1_2a87e00.go +++ b/clients/crunchbase/index/sha1_2a87e00.go @@ -289,10 +289,14 @@ func (r RefOfMapOfStringToRefOfCompany) ChildValues() []types.Value { // A Noms Value that describes RefOfMapOfStringToRefOfCompany. var __typeForRefOfMapOfStringToRefOfCompany types.Type -func (m RefOfMapOfStringToRefOfCompany) Type() types.Type { +func (r RefOfMapOfStringToRefOfCompany) Type() types.Type { return __typeForRefOfMapOfStringToRefOfCompany } +func (r RefOfMapOfStringToRefOfCompany) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfMapOfStringToRefOfCompany = types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.MapKind, types.MakePrimitiveType(types.StringKind), types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-9fb26a609a1d4134935888c9676c79d6ea89acbb"), 0)))) types.RegisterRef(__typeForRefOfMapOfStringToRefOfCompany, builderForRefOfMapOfStringToRefOfCompany) @@ -480,10 +484,14 @@ func (r RefOfCompany) ChildValues() []types.Value { // A Noms Value that describes RefOfCompany. var __typeForRefOfCompany types.Type -func (m RefOfCompany) Type() types.Type { +func (r RefOfCompany) Type() types.Type { return __typeForRefOfCompany } +func (r RefOfCompany) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfCompany = types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-9fb26a609a1d4134935888c9676c79d6ea89acbb"), 0)) types.RegisterRef(__typeForRefOfCompany, builderForRefOfCompany) diff --git a/clients/crunchbase/index/sha1_9fb26a6.go b/clients/crunchbase/index/sha1_9fb26a6.go index f34f7df413..96ae98e7d3 100644 --- a/clients/crunchbase/index/sha1_9fb26a6.go +++ b/clients/crunchbase/index/sha1_9fb26a6.go @@ -947,10 +947,14 @@ func (r RefOfRound) ChildValues() []types.Value { // A Noms Value that describes RefOfRound. var __typeForRefOfRound types.Type -func (m RefOfRound) Type() types.Type { +func (r RefOfRound) Type() types.Type { return __typeForRefOfRound } +func (r RefOfRound) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfRound = types.MakeCompoundType(types.RefKind, types.MakeType(__mainPackageInFile_sha1_9fb26a6_CachedRef, 1)) types.RegisterRef(__typeForRefOfRound, builderForRefOfRound) diff --git a/clients/flickr/types.noms.go b/clients/flickr/types.noms.go index bf026f29d6..0cfd6c7df8 100644 --- a/clients/flickr/types.noms.go +++ b/clients/flickr/types.noms.go @@ -503,10 +503,14 @@ func (r RefOfUser) ChildValues() []types.Value { // A Noms Value that describes RefOfUser. var __typeForRefOfUser types.Type -func (m RefOfUser) Type() types.Type { +func (r RefOfUser) Type() types.Type { return __typeForRefOfUser } +func (r RefOfUser) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfUser = types.MakeCompoundType(types.RefKind, types.MakeType(__mainPackageInFile_types_CachedRef, 0)) types.RegisterRef(__typeForRefOfUser, builderForRefOfUser) @@ -560,10 +564,14 @@ func (r RefOfSetOfRefOfRemotePhoto) ChildValues() []types.Value { // A Noms Value that describes RefOfSetOfRefOfRemotePhoto. var __typeForRefOfSetOfRefOfRemotePhoto types.Type -func (m RefOfSetOfRefOfRemotePhoto) Type() types.Type { +func (r RefOfSetOfRefOfRemotePhoto) Type() types.Type { return __typeForRefOfSetOfRefOfRemotePhoto } +func (r RefOfSetOfRefOfRemotePhoto) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfSetOfRefOfRemotePhoto = types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.SetKind, types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-42722c55cec055ff32526d1dc0636fa4d48c9fd5"), 0)))) types.RegisterRef(__typeForRefOfSetOfRefOfRemotePhoto, builderForRefOfSetOfRefOfRemotePhoto) @@ -767,10 +775,14 @@ func (r RefOfRemotePhoto) ChildValues() []types.Value { // A Noms Value that describes RefOfRemotePhoto. var __typeForRefOfRemotePhoto types.Type -func (m RefOfRemotePhoto) Type() types.Type { +func (r RefOfRemotePhoto) Type() types.Type { return __typeForRefOfRemotePhoto } +func (r RefOfRemotePhoto) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfRemotePhoto = types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-42722c55cec055ff32526d1dc0636fa4d48c9fd5"), 0)) types.RegisterRef(__typeForRefOfRemotePhoto, builderForRefOfRemotePhoto) diff --git a/clients/picasa/picasa.noms.go b/clients/picasa/picasa.noms.go index ae963082a6..56ae2b0938 100644 --- a/clients/picasa/picasa.noms.go +++ b/clients/picasa/picasa.noms.go @@ -672,10 +672,14 @@ func (r RefOfUser) ChildValues() []types.Value { // A Noms Value that describes RefOfUser. var __typeForRefOfUser types.Type -func (m RefOfUser) Type() types.Type { +func (r RefOfUser) Type() types.Type { return __typeForRefOfUser } +func (r RefOfUser) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfUser = types.MakeCompoundType(types.RefKind, types.MakeType(__mainPackageInFile_picasa_CachedRef, 0)) types.RegisterRef(__typeForRefOfUser, builderForRefOfUser) @@ -729,10 +733,14 @@ func (r RefOfSetOfRefOfRemotePhoto) ChildValues() []types.Value { // A Noms Value that describes RefOfSetOfRefOfRemotePhoto. var __typeForRefOfSetOfRefOfRemotePhoto types.Type -func (m RefOfSetOfRefOfRemotePhoto) Type() types.Type { +func (r RefOfSetOfRefOfRemotePhoto) Type() types.Type { return __typeForRefOfSetOfRefOfRemotePhoto } +func (r RefOfSetOfRefOfRemotePhoto) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfSetOfRefOfRemotePhoto = types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.SetKind, types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-42722c55cec055ff32526d1dc0636fa4d48c9fd5"), 0)))) types.RegisterRef(__typeForRefOfSetOfRefOfRemotePhoto, builderForRefOfSetOfRefOfRemotePhoto) @@ -936,10 +944,14 @@ func (r RefOfRemotePhoto) ChildValues() []types.Value { // A Noms Value that describes RefOfRemotePhoto. var __typeForRefOfRemotePhoto types.Type -func (m RefOfRemotePhoto) Type() types.Type { +func (r RefOfRemotePhoto) Type() types.Type { return __typeForRefOfRemotePhoto } +func (r RefOfRemotePhoto) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfRemotePhoto = types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-42722c55cec055ff32526d1dc0636fa4d48c9fd5"), 0)) types.RegisterRef(__typeForRefOfRemotePhoto, builderForRefOfRemotePhoto) diff --git a/clients/pitchmap/index/types.noms.go b/clients/pitchmap/index/types.noms.go index 1be33f7464..e87d9184b4 100644 --- a/clients/pitchmap/index/types.noms.go +++ b/clients/pitchmap/index/types.noms.go @@ -447,10 +447,14 @@ func (r RefOfMapOfStringToValue) ChildValues() []types.Value { // A Noms Value that describes RefOfMapOfStringToValue. var __typeForRefOfMapOfStringToValue types.Type -func (m RefOfMapOfStringToValue) Type() types.Type { +func (r RefOfMapOfStringToValue) Type() types.Type { return __typeForRefOfMapOfStringToValue } +func (r RefOfMapOfStringToValue) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfMapOfStringToValue = types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.MapKind, types.MakePrimitiveType(types.StringKind), types.MakePrimitiveType(types.ValueKind))) types.RegisterRef(__typeForRefOfMapOfStringToValue, builderForRefOfMapOfStringToValue) @@ -781,10 +785,14 @@ func (r RefOfListOfPitch) ChildValues() []types.Value { // A Noms Value that describes RefOfListOfPitch. var __typeForRefOfListOfPitch types.Type -func (m RefOfListOfPitch) Type() types.Type { +func (r RefOfListOfPitch) Type() types.Type { return __typeForRefOfListOfPitch } +func (r RefOfListOfPitch) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfListOfPitch = types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.ListKind, types.MakeType(__mainPackageInFile_types_CachedRef, 0))) types.RegisterRef(__typeForRefOfListOfPitch, builderForRefOfListOfPitch) diff --git a/clients/tagdex/types.noms.go b/clients/tagdex/types.noms.go index 4fd4a50e3b..a2301298fe 100644 --- a/clients/tagdex/types.noms.go +++ b/clients/tagdex/types.noms.go @@ -328,10 +328,14 @@ func (r RefOfRemotePhoto) ChildValues() []types.Value { // A Noms Value that describes RefOfRemotePhoto. var __typeForRefOfRemotePhoto types.Type -func (m RefOfRemotePhoto) Type() types.Type { +func (r RefOfRemotePhoto) Type() types.Type { return __typeForRefOfRemotePhoto } +func (r RefOfRemotePhoto) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfRemotePhoto = types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-42722c55cec055ff32526d1dc0636fa4d48c9fd5"), 0)) types.RegisterRef(__typeForRefOfRemotePhoto, builderForRefOfRemotePhoto) diff --git a/clients/util/types.noms.go b/clients/util/types.noms.go index 90b4c49ebe..fb5e276440 100644 --- a/clients/util/types.noms.go +++ b/clients/util/types.noms.go @@ -187,10 +187,14 @@ func (r RefOfMapOfStringToValue) ChildValues() []types.Value { // A Noms Value that describes RefOfMapOfStringToValue. var __typeForRefOfMapOfStringToValue types.Type -func (m RefOfMapOfStringToValue) Type() types.Type { +func (r RefOfMapOfStringToValue) Type() types.Type { return __typeForRefOfMapOfStringToValue } +func (r RefOfMapOfStringToValue) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfMapOfStringToValue = types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.MapKind, types.MakePrimitiveType(types.StringKind), types.MakePrimitiveType(types.ValueKind))) types.RegisterRef(__typeForRefOfMapOfStringToValue, builderForRefOfMapOfStringToValue) diff --git a/datas/types.noms.go b/datas/types.noms.go index 995280036f..eb7541f069 100644 --- a/datas/types.noms.go +++ b/datas/types.noms.go @@ -456,10 +456,14 @@ func (r RefOfCommit) ChildValues() []types.Value { // A Noms Value that describes RefOfCommit. var __typeForRefOfCommit types.Type -func (m RefOfCommit) Type() types.Type { +func (r RefOfCommit) Type() types.Type { return __typeForRefOfCommit } +func (r RefOfCommit) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfCommit = types.MakeCompoundType(types.RefKind, types.MakeType(__datasPackageInFile_types_CachedRef, 0)) types.RegisterRef(__typeForRefOfCommit, builderForRefOfCommit) diff --git a/nomdl/codegen/ref.tmpl b/nomdl/codegen/ref.tmpl index 33095e5858..0123ffa7e3 100644 --- a/nomdl/codegen/ref.tmpl +++ b/nomdl/codegen/ref.tmpl @@ -36,10 +36,14 @@ func (r {{.Name}}) ChildValues() []{{$typesPackage}}Value { // A Noms Value that describes {{.Name}}. var __typeFor{{.Name}} {{$typesPackage}}Type -func (m {{.Name}}) Type() {{$typesPackage}}Type { +func (r {{.Name}}) Type() {{$typesPackage}}Type { return __typeFor{{.Name}} } +func (r {{.Name}}) Less(other {{$typesPackage}}OrderedValue) bool { + return r.TargetRef().Less(other.({{$typesPackage}}RefBase).TargetRef()) +} + func init() { __typeFor{{.Name}} = {{toTypesType .Type .FileID .PackageName}} {{$typesPackage}}RegisterRef(__typeFor{{.Name}}, builderFor{{.Name}}) diff --git a/nomdl/codegen/test/gen/ref.noms.go b/nomdl/codegen/test/gen/ref.noms.go index f05d03cc76..ddebefea53 100644 --- a/nomdl/codegen/test/gen/ref.noms.go +++ b/nomdl/codegen/test/gen/ref.noms.go @@ -151,10 +151,14 @@ func (r RefOfListOfString) ChildValues() []types.Value { // A Noms Value that describes RefOfListOfString. var __typeForRefOfListOfString types.Type -func (m RefOfListOfString) Type() types.Type { +func (r RefOfListOfString) Type() types.Type { return __typeForRefOfListOfString } +func (r RefOfListOfString) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfListOfString = types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.StringKind))) types.RegisterRef(__typeForRefOfListOfString, builderForRefOfListOfString) @@ -351,10 +355,14 @@ func (r RefOfSetOfFloat32) ChildValues() []types.Value { // A Noms Value that describes RefOfSetOfFloat32. var __typeForRefOfSetOfFloat32 types.Type -func (m RefOfSetOfFloat32) Type() types.Type { +func (r RefOfSetOfFloat32) Type() types.Type { return __typeForRefOfSetOfFloat32 } +func (r RefOfSetOfFloat32) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfSetOfFloat32 = types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.SetKind, types.MakePrimitiveType(types.Float32Kind))) types.RegisterRef(__typeForRefOfSetOfFloat32, builderForRefOfSetOfFloat32) @@ -551,10 +559,14 @@ func (r RefOfFloat32) ChildValues() []types.Value { // A Noms Value that describes RefOfFloat32. var __typeForRefOfFloat32 types.Type -func (m RefOfFloat32) Type() types.Type { +func (r RefOfFloat32) Type() types.Type { return __typeForRefOfFloat32 } +func (r RefOfFloat32) Less(other types.OrderedValue) bool { + return r.TargetRef().Less(other.(types.RefBase).TargetRef()) +} + func init() { __typeForRefOfFloat32 = types.MakeCompoundType(types.RefKind, types.MakePrimitiveType(types.Float32Kind)) types.RegisterRef(__typeForRefOfFloat32, builderForRefOfFloat32) diff --git a/nomdl/pkg/gen/generate_parser.sh b/nomdl/pkg/gen/generate_parser.sh index 5d01bc63b3..420d7b7b05 100755 --- a/nomdl/pkg/gen/generate_parser.sh +++ b/nomdl/pkg/gen/generate_parser.sh @@ -1,3 +1,3 @@ #! /bin/sh -pigeon "${1}" | goimports > "${1}".go \ No newline at end of file +"$GOPATH/bin/pigeon" "${1}" | "$GOPATH/bin/goimports" > "${1}".go diff --git a/types/compound_map_test.go b/types/compound_map_test.go index fbf066e6b6..3598ff7e8f 100644 --- a/types/compound_map_test.go +++ b/types/compound_map_test.go @@ -9,154 +9,153 @@ import ( "github.com/attic-labs/noms/chunks" ) -type testNativeOrderMap []mapEntry - -func (tm testNativeOrderMap) Len() int { - return len(tm) +type testMap struct { + entries []mapEntry + less testMapLessFn + tr Type } -func (tm testNativeOrderMap) Less(i, j int) bool { - return tm[i].key.(OrderedValue).Less(tm[j].key.(OrderedValue)) +type testMapLessFn func(x, y Value) bool + +func (tm testMap) Len() int { + return len(tm.entries) } -func (tm testNativeOrderMap) Swap(i, j int) { - tm[i], tm[j] = tm[j], tm[i] +func (tm testMap) Less(i, j int) bool { + return tm.less(tm.entries[i].key, tm.entries[j].key) } -func getTestNativeOrderMap() ([]mapEntry, []Value) { - length := int(mapPattern * 16) - s := rand.NewSource(42) +func (tm testMap) Swap(i, j int) { + tm.entries[i], tm.entries[j] = tm.entries[j], tm.entries[i] +} + +func (tm testMap) toCompoundMap(cs chunks.ChunkStore) compoundMap { + keyvals := []Value{} + for _, entry := range tm.entries { + keyvals = append(keyvals, entry.key, entry.value) + } + return NewTypedMap(cs, tm.tr, keyvals...).(compoundMap) +} + +type testMapGenFn func(v Int64) Value + +func newTestMap(length int, gen testMapGenFn, less testMapLessFn, tr Type) testMap { + s := rand.NewSource(4242) used := map[int64]bool{} - mapData := testNativeOrderMap{} - values := []Value{} - - for len(values) < length { + var entries []mapEntry + for len(entries) < length { v := s.Int63() & 0xffffff if _, ok := used[v]; !ok { - entry := mapEntry{Int64(v), Int64(v * 2)} - mapData = append(mapData, entry) + entry := mapEntry{gen(Int64(v)), gen(Int64(v * 2))} + entries = append(entries, entry) used[v] = true - values = append(values, entry.key, entry.value) } } - sort.Sort(mapData) - return mapData, values + return testMap{entries, less, MakeCompoundType(MapKind, tr, tr)} } -type testRefOrderMap []mapEntry - -func (tm testRefOrderMap) Len() int { - return len(tm) +func getTestNativeOrderMap() testMap { + return newTestMap(int(mapPattern*16), func(v Int64) Value { + return v + }, func(x, y Value) bool { + return !y.(OrderedValue).Less(x.(OrderedValue)) + }, MakePrimitiveType(Int64Kind)) } -func (tm testRefOrderMap) Less(i, j int) bool { - return tm[i].key.Ref().Less(tm[j].key.Ref()) +func getTestRefValueOrderMap() testMap { + setType := MakeCompoundType(SetKind, MakePrimitiveType(Int64Kind)) + return newTestMap(int(mapPattern*2), func(v Int64) Value { + return NewTypedSet(chunks.NewMemoryStore(), setType, v) + }, func(x, y Value) bool { + return !y.Ref().Less(x.Ref()) + }, setType) } -func (tm testRefOrderMap) Swap(i, j int) { - tm[i], tm[j] = tm[j], tm[i] +func getTestRefToNativeOrderMap() testMap { + refType := MakeCompoundType(RefKind, MakePrimitiveType(Int64Kind)) + return newTestMap(int(mapPattern*2), func(v Int64) Value { + return newRef(v.Ref(), refType) + }, func(x, y Value) bool { + return !y.(RefBase).TargetRef().Less(x.(RefBase).TargetRef()) + }, refType) } -func getTestRefOrderMap() ([]mapEntry, []Value) { - length := int(mapPattern * 16) - s := rand.NewSource(42) - used := map[int64]bool{} - - values := []Value{} - mapData := testRefOrderMap{} - for i := 0; i < length; i++ { - v := s.Int63() & 0xffffff - if _, ok := used[v]; !ok { - entry := mapEntry{NewRef(Int64(v).Ref()), Int64(v)} - mapData = append(mapData, entry) - used[v] = true - values = append(values, entry.key, entry.value) - } - } - - sort.Sort(mapData) - return mapData, values +func getTestRefToValueOrderMap() testMap { + setType := MakeCompoundType(SetKind, MakePrimitiveType(Int64Kind)) + refType := MakeCompoundType(RefKind, setType) + return newTestMap(int(mapPattern*2), func(v Int64) Value { + return newRef(NewTypedSet(chunks.NewMemoryStore(), setType, v).Ref(), refType) + }, func(x, y Value) bool { + return !y.(RefBase).TargetRef().Less(x.(RefBase).TargetRef()) + }, refType) } -func TestCompoundMapHasAndGet(t *testing.T) { +func TestCompoundMapHas(t *testing.T) { assert := assert.New(t) - cs := chunks.NewMemoryStore() - - doTest := func(simpleMap []mapEntry, m compoundMap) { - for _, v := range simpleMap { - assert.True(m.Has(v.key)) - assert.True(m.Get(v.key).Equals(v.value)) + doTest := func(tm testMap) { + m := tm.toCompoundMap(chunks.NewMemoryStore()) + for _, entry := range tm.entries { + assert.True(m.Has(entry.key)) + assert.True(m.Get(entry.key).Equals(entry.value)) } } - simpleMap, kv := getTestNativeOrderMap() - tr := MakeCompoundType(MapKind, MakePrimitiveType(Int64Kind), MakePrimitiveType(Int64Kind)) - m := NewTypedMap(cs, tr, kv...).(compoundMap) - doTest(simpleMap, m) - - simpleMap, kv = getTestRefOrderMap() - tr = MakeCompoundType(MapKind, MakeCompoundType(RefKind, MakePrimitiveType(ValueKind)), MakePrimitiveType(Int64Kind)) - m = NewTypedMap(cs, tr, kv...).(compoundMap) - doTest(simpleMap, m) + doTest(getTestNativeOrderMap()) + doTest(getTestRefValueOrderMap()) + doTest(getTestRefToNativeOrderMap()) + doTest(getTestRefToValueOrderMap()) } func TestCompoundMapIter(t *testing.T) { assert := assert.New(t) - cs := chunks.NewMemoryStore() - - doTest := func(simpleMap []mapEntry, m compoundMap) { + doTest := func(tm testMap) { + m := tm.toCompoundMap(chunks.NewMemoryStore()) + sort.Sort(tm) idx := uint64(0) endAt := uint64(mapPattern) m.Iter(func(k, v Value) bool { - assert.True(simpleMap[idx].key.Equals(k)) - assert.True(simpleMap[idx].value.Equals(v)) + assert.True(tm.entries[idx].key.Equals(k)) + assert.True(tm.entries[idx].value.Equals(v)) if idx == endAt { + idx += 1 return true } - idx++ + + idx += 1 return false }) - assert.Equal(endAt, idx) + assert.Equal(endAt, idx-1) } - simpleMap, kv := getTestNativeOrderMap() - tr := MakeCompoundType(MapKind, MakePrimitiveType(Int64Kind), MakePrimitiveType(Int64Kind)) - m := NewTypedMap(cs, tr, kv...).(compoundMap) - doTest(simpleMap, m) - - simpleMap, kv = getTestRefOrderMap() - tr = MakeCompoundType(MapKind, MakeCompoundType(RefKind, MakePrimitiveType(ValueKind)), MakePrimitiveType(Int64Kind)) - m = NewTypedMap(cs, tr, kv...).(compoundMap) - doTest(simpleMap, m) + doTest(getTestNativeOrderMap()) + doTest(getTestRefValueOrderMap()) + doTest(getTestRefToNativeOrderMap()) + doTest(getTestRefToValueOrderMap()) } func TestCompoundMapIterAll(t *testing.T) { assert := assert.New(t) - cs := chunks.NewMemoryStore() - - doTest := func(simpleMap []mapEntry, m compoundMap) { + doTest := func(tm testMap) { + m := tm.toCompoundMap(chunks.NewMemoryStore()) + sort.Sort(tm) idx := uint64(0) + m.IterAll(func(k, v Value) { - assert.True(simpleMap[idx].key.Equals(k)) - assert.True(simpleMap[idx].value.Equals(v)) + assert.True(tm.entries[idx].key.Equals(k)) + assert.True(tm.entries[idx].value.Equals(v)) idx++ }) } - simpleMap, kv := getTestNativeOrderMap() - tr := MakeCompoundType(MapKind, MakePrimitiveType(Int64Kind), MakePrimitiveType(Int64Kind)) - m := NewTypedMap(cs, tr, kv...).(compoundMap) - doTest(simpleMap, m) - - simpleMap, kv = getTestRefOrderMap() - tr = MakeCompoundType(MapKind, MakeCompoundType(RefKind, MakePrimitiveType(ValueKind)), MakePrimitiveType(Int64Kind)) - m = NewTypedMap(cs, tr, kv...).(compoundMap) - doTest(simpleMap, m) + doTest(getTestNativeOrderMap()) + doTest(getTestRefValueOrderMap()) + doTest(getTestRefToNativeOrderMap()) + doTest(getTestRefToValueOrderMap()) } diff --git a/types/compound_set_test.go b/types/compound_set_test.go index 3b3db286fb..051faad0a3 100644 --- a/types/compound_set_test.go +++ b/types/compound_set_test.go @@ -9,103 +9,111 @@ import ( "github.com/attic-labs/noms/chunks" ) -type testNativeOrderSet []Value - -func (tss testNativeOrderSet) Len() int { - return len(tss) +type testSet struct { + values []Value + less testSetLessFn + tr Type } -func (tss testNativeOrderSet) Less(i, j int) bool { - return tss[i].(OrderedValue).Less(tss[j].(OrderedValue)) +type testSetLessFn func(x, y Value) bool + +func (ts testSet) Len() int { + return len(ts.values) } -func (tss testNativeOrderSet) Swap(i, j int) { - tss[i], tss[j] = tss[j], tss[i] +func (ts testSet) Less(i, j int) bool { + return ts.less(ts.values[i], ts.values[j]) } -func getTestNativeOrderSet() []Value { - length := int(setPattern * 16) - s := rand.NewSource(42) +func (ts testSet) Swap(i, j int) { + ts.values[i], ts.values[j] = ts.values[j], ts.values[i] +} + +func (ts testSet) toCompoundSet(cs chunks.ChunkStore) compoundSet { + return NewTypedSet(cs, ts.tr, ts.values...).(compoundSet) +} + +type testSetGenFn func(v Int64) Value + +func newTestSet(length int, gen testSetGenFn, less testSetLessFn, tr Type) testSet { + s := rand.NewSource(4242) used := map[int64]bool{} - values := testNativeOrderSet{} + var values []Value for len(values) < length { v := s.Int63() & 0xffffff if _, ok := used[v]; !ok { - values = append(values, Int64(v)) + values = append(values, gen(Int64(v))) used[v] = true } } - sort.Sort(values) - return values + return testSet{values, less, MakeCompoundType(SetKind, tr)} } -type testRefOrderSet []Value - -func (tss testRefOrderSet) Len() int { - return len(tss) +func getTestNativeOrderSet() testSet { + return newTestSet(int(setPattern*16), func(v Int64) Value { + return v + }, func(x, y Value) bool { + return !y.(OrderedValue).Less(x.(OrderedValue)) + }, MakePrimitiveType(Int64Kind)) } -func (tss testRefOrderSet) Less(i, j int) bool { - return tss[i].Ref().Less(tss[j].Ref()) +func getTestRefValueOrderSet() testSet { + setType := MakeCompoundType(SetKind, MakePrimitiveType(Int64Kind)) + return newTestSet(int(setPattern*2), func(v Int64) Value { + return NewTypedSet(chunks.NewMemoryStore(), setType, v) + }, func(x, y Value) bool { + return !y.Ref().Less(x.Ref()) + }, setType) } -func (tss testRefOrderSet) Swap(i, j int) { - tss[i], tss[j] = tss[j], tss[i] +func getTestRefToNativeOrderSet() testSet { + refType := MakeCompoundType(RefKind, MakePrimitiveType(Int64Kind)) + return newTestSet(int(setPattern*2), func(v Int64) Value { + return newRef(v.Ref(), refType) + }, func(x, y Value) bool { + return !y.(RefBase).TargetRef().Less(x.(RefBase).TargetRef()) + }, refType) } -func getTestRefOrderSet() []Value { - length := int(setPattern * 2) - s := rand.NewSource(42) - used := map[int64]bool{} - - values := testRefOrderSet{} - for i := 0; i < length; i++ { - v := s.Int63() & 0xffffff - if _, ok := used[v]; !ok { - values = append(values, NewRef(Int64(v).Ref())) - used[v] = true - } - } - - sort.Sort(values) - return values +func getTestRefToValueOrderSet() testSet { + setType := MakeCompoundType(SetKind, MakePrimitiveType(Int64Kind)) + refType := MakeCompoundType(RefKind, setType) + return newTestSet(int(setPattern*2), func(v Int64) Value { + return newRef(NewTypedSet(chunks.NewMemoryStore(), setType, v).Ref(), refType) + }, func(x, y Value) bool { + return !y.(RefBase).TargetRef().Less(x.(RefBase).TargetRef()) + }, refType) } func TestCompoundSetHas(t *testing.T) { assert := assert.New(t) - cs := chunks.NewMemoryStore() - - doTest := func(simpleSet []Value, set compoundSet) { - for _, v := range simpleSet { + doTest := func(ts testSet) { + set := ts.toCompoundSet(chunks.NewMemoryStore()) + for _, v := range ts.values { assert.True(set.Has(v)) } } - simpleSet := getTestNativeOrderSet() - tr := MakeCompoundType(SetKind, MakePrimitiveType(Int64Kind)) - set := NewTypedSet(cs, tr, simpleSet...).(compoundSet) - doTest(simpleSet, set) - - simpleSet = getTestRefOrderSet() - tr = MakeCompoundType(SetKind, MakeCompoundType(RefKind, MakePrimitiveType(ValueKind))) - set = NewTypedSet(cs, tr, simpleSet...).(compoundSet) - doTest(simpleSet, set) + doTest(getTestNativeOrderSet()) + doTest(getTestRefValueOrderSet()) + doTest(getTestRefToNativeOrderSet()) + doTest(getTestRefToValueOrderSet()) } func TestCompoundSetIter(t *testing.T) { assert := assert.New(t) - cs := chunks.NewMemoryStore() - - doTest := func(simpleSet []Value, set compoundSet) { + doTest := func(ts testSet) { + set := ts.toCompoundSet(chunks.NewMemoryStore()) + sort.Sort(ts) idx := uint64(0) endAt := uint64(setPattern) set.Iter(func(v Value) bool { - assert.True(simpleSet[idx].Equals(v)) + assert.True(ts.values[idx].Equals(v)) if idx == endAt { idx += 1 return true @@ -118,40 +126,28 @@ func TestCompoundSetIter(t *testing.T) { assert.Equal(endAt, idx-1) } - simpleSet := getTestNativeOrderSet() - tr := MakeCompoundType(SetKind, MakePrimitiveType(Int64Kind)) - set := NewTypedSet(cs, tr, simpleSet...).(compoundSet) - doTest(simpleSet, set) - - simpleSet = getTestRefOrderSet() - tr = MakeCompoundType(SetKind, MakeCompoundType(RefKind, MakePrimitiveType(ValueKind))) - set = NewTypedSet(cs, tr, simpleSet...).(compoundSet) - doTest(simpleSet, set) + doTest(getTestNativeOrderSet()) + doTest(getTestRefValueOrderSet()) + doTest(getTestRefToNativeOrderSet()) + doTest(getTestRefToValueOrderSet()) } func TestCompoundSetIterAll(t *testing.T) { - if testing.Short() { - t.Skip("Skipping test in short mode.") - } assert := assert.New(t) - cs := chunks.NewMemoryStore() - - doTest := func(simpleSet []Value, set compoundSet) { + doTest := func(ts testSet) { + set := ts.toCompoundSet(chunks.NewMemoryStore()) + sort.Sort(ts) idx := uint64(0) + set.IterAll(func(v Value) { - assert.True(simpleSet[idx].Equals(v)) + assert.True(ts.values[idx].Equals(v)) idx++ }) } - simpleSet := getTestNativeOrderSet() - tr := MakeCompoundType(SetKind, MakePrimitiveType(Int64Kind)) - set := NewTypedSet(cs, tr, simpleSet...).(compoundSet) - doTest(simpleSet, set) - - simpleSet = getTestRefOrderSet() - tr = MakeCompoundType(SetKind, MakeCompoundType(RefKind, MakePrimitiveType(ValueKind))) - set = NewTypedSet(cs, tr, simpleSet...).(compoundSet) - doTest(simpleSet, set) + doTest(getTestNativeOrderSet()) + doTest(getTestRefValueOrderSet()) + doTest(getTestRefToNativeOrderSet()) + doTest(getTestRefToValueOrderSet()) } diff --git a/types/package_set_of_ref.go b/types/package_set_of_ref.go index eb02a8568b..6ec276aaf2 100644 --- a/types/package_set_of_ref.go +++ b/types/package_set_of_ref.go @@ -197,6 +197,10 @@ func (m RefOfPackage) Type() Type { return __typeForRefOfPackage } +func (r RefOfPackage) Less(other OrderedValue) bool { + return r.TargetRef().Less(other.(RefBase).TargetRef()) +} + func init() { __typeForRefOfPackage = MakeCompoundType(RefKind, MakePrimitiveType(PackageKind)) RegisterRef(__typeForRefOfPackage, builderForRefOfPackage) diff --git a/types/ref.go b/types/ref.go index 667ee97958..8c87331ac8 100644 --- a/types/ref.go +++ b/types/ref.go @@ -49,6 +49,10 @@ func (r Ref) Type() Type { return r.t } +func (r Ref) Less(other OrderedValue) bool { + return r.target.Less(other.(Ref).target) +} + func (r Ref) TargetValue(cs chunks.ChunkStore) Value { return ReadValue(r.target, cs) } diff --git a/types/type.go b/types/type.go index 4a2b6e4da8..955861f28a 100644 --- a/types/type.go +++ b/types/type.go @@ -69,10 +69,12 @@ func (t Type) Kind() NomsKind { } func (t Type) IsOrdered() bool { - if desc, ok := t.Desc.(PrimitiveDesc); ok { - return desc.IsOrdered() + switch t.Desc.Kind() { + case Float32Kind, Float64Kind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, Uint8Kind, Uint16Kind, Uint32Kind, Uint64Kind, StringKind, RefKind: + return true + default: + return false } - return false } func (t Type) PackageRef() ref.Ref { diff --git a/types/type_desc.go b/types/type_desc.go index 169dd0a36e..e0d0f774f6 100644 --- a/types/type_desc.go +++ b/types/type_desc.go @@ -46,15 +46,6 @@ func (p PrimitiveDesc) Describe() string { return KindToString[p.Kind()] } -func (p PrimitiveDesc) IsOrdered() bool { - switch p.Kind() { - case Float32Kind, Float64Kind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, Uint8Kind, Uint16Kind, Uint32Kind, Uint64Kind, StringKind: - return true - default: - return false - } -} - var KindToString = map[NomsKind]string{ BlobKind: "Blob", BoolKind: "Bool", diff --git a/types/type_test.go b/types/type_test.go index 729f37db0c..127ac97b30 100644 --- a/types/type_test.go +++ b/types/type_test.go @@ -110,5 +110,5 @@ func TestTypeOrdered(t *testing.T) { assert.False(MakeCompoundType(ListKind, MakePrimitiveType(StringKind)).IsOrdered()) assert.False(MakeCompoundType(SetKind, MakePrimitiveType(StringKind)).IsOrdered()) assert.False(MakeCompoundType(MapKind, MakePrimitiveType(StringKind), MakePrimitiveType(ValueKind)).IsOrdered()) - assert.False(MakeCompoundType(RefKind, MakePrimitiveType(StringKind)).IsOrdered()) + assert.True(MakeCompoundType(RefKind, MakePrimitiveType(StringKind)).IsOrdered()) }