Skip to content

Commit

Permalink
Merge pull request #1578 from hashicorp/b-scrict-less
Browse files Browse the repository at this point in the history
sort: use strictly less-than for less implementations
  • Loading branch information
shoenig authored May 2, 2022
2 parents 38ffca4 + ef04a6e commit 7ecad12
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 31 deletions.
2 changes: 1 addition & 1 deletion config/nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

import "fmt"

// NomadConfig is the configuration for connecto to a Nomad agent.
// NomadConfig is the configuration for connecting to a Nomad agent.
type NomadConfig struct {
// Address is the URI to the Nomad agent.
Address *string `mapstructure:"address"`
Expand Down
4 changes: 2 additions & 2 deletions dependency/catalog_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (s ByService) Len() int { return len(s) }
func (s ByService) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s ByService) Less(i, j int) bool {
if s[i].Service == s[j].Service {
return s[i].ID <= s[j].ID
return s[i].ID < s[j].ID
}
return s[i].Service <= s[j].Service
return s[i].Service < s[j].Service
}
4 changes: 2 additions & 2 deletions dependency/catalog_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (s ByNode) Len() int { return len(s) }
func (s ByNode) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s ByNode) Less(i, j int) bool {
if s[i].Node == s[j].Node {
return s[i].Address <= s[j].Address
return s[i].Address < s[j].Address
}
return s[i].Node <= s[j].Node
return s[i].Node < s[j].Node
}
11 changes: 3 additions & 8 deletions dependency/catalog_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ func (d *CatalogServicesQuery) Type() Type {
// ByName is a sortable slice of CatalogService structs.
type ByName []*CatalogSnippet

func (s ByName) Len() int { return len(s) }
func (s ByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s ByName) Less(i, j int) bool {
if s[i].Name <= s[j].Name {
return true
}
return false
}
func (s ByName) Len() int { return len(s) }
func (s ByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s ByName) Less(i, j int) bool { return s[i].Name < s[j].Name }
2 changes: 1 addition & 1 deletion dependency/health_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (s ByNodeThenID) Less(i, j int) bool {
if s[i].Node < s[j].Node {
return true
} else if s[i].Node == s[j].Node {
return s[i].ID <= s[j].ID
return s[i].ID < s[j].ID
}
return false
}
11 changes: 3 additions & 8 deletions dependency/nomad_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ func (d *NomadServiceQuery) Type() Type {
// NomadServiceByName is a sortable slice of NomadService structs.
type NomadServiceByName []*NomadService

func (s NomadServiceByName) Len() int { return len(s) }
func (s NomadServiceByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s NomadServiceByName) Less(i, j int) bool {
if s[i].Name <= s[j].Name {
return true
}
return false
}
func (s NomadServiceByName) Len() int { return len(s) }
func (s NomadServiceByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s NomadServiceByName) Less(i, j int) bool { return s[i].Name < s[j].Name }
11 changes: 3 additions & 8 deletions dependency/nomad_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@ type NomadServicesSnippet struct {
// nomadSortableSnippet is a sortable slice of NomadServicesSnippet structs.
type nomadSortableSnippet []*NomadServicesSnippet

func (s nomadSortableSnippet) Len() int { return len(s) }
func (s nomadSortableSnippet) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s nomadSortableSnippet) Less(i, j int) bool {
if s[i].Name <= s[j].Name {
return true
}
return false
}
func (s nomadSortableSnippet) Len() int { return len(s) }
func (s nomadSortableSnippet) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s nomadSortableSnippet) Less(i, j int) bool { return s[i].Name < s[j].Name }

// NomadServicesQuery is the representation of a requested Nomad service
// dependency from inside a template.
Expand Down
2 changes: 1 addition & 1 deletion template/brain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewBrain() *Brain {

// Remember accepts a dependency and the data to store associated with that
// dep. This function converts the given data to a proper type and stores
// it interally.
// it internally.
func (b *Brain) Remember(d dep.Dependency, data interface{}) {
b.Lock()
defer b.Unlock()
Expand Down

0 comments on commit 7ecad12

Please sign in to comment.