Skip to content

Commit

Permalink
feat(go/inventory): implement sort for gpu info (#118)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Feb 1, 2024
1 parent d973e75 commit 46338c2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions go/inventory/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ClusterStorage []Storage
var _ sort.Interface = (*Nodes)(nil)
var _ sort.Interface = (*GPUs)(nil)
var _ sort.Interface = (*CPUInfoS)(nil)
var _ sort.Interface = (*GPUInfoS)(nil)
var _ sort.Interface = (*ClusterStorage)(nil)

func (s Nodes) Len() int {
Expand Down Expand Up @@ -57,6 +58,32 @@ func (s CPUInfoS) Less(i, j int) bool {
return false
}

func (s GPUInfoS) Len() int {
return len(s)
}

func (s GPUInfoS) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

func (s GPUInfoS) Less(i, j int) bool {
a, b := s[i], s[j]

if a.Vendor != b.Vendor {
return a.Vendor < b.Vendor
}

if a.Name != b.Name {
return a.Name < b.Name
}

if a.MemorySize != b.MemorySize {
return a.MemorySize < b.MemorySize
}

return false
}

func (s GPUs) Len() int {
return len(s)
}
Expand Down

0 comments on commit 46338c2

Please sign in to comment.