From 5ac13b6824a65b82ae6e2b4ed13643a3e572983a Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Thu, 1 Feb 2024 15:34:28 -0500 Subject: [PATCH] feat(go/inventory): implement sort for gpu info Signed-off-by: Artur Troian --- go/inventory/v1/types.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/go/inventory/v1/types.go b/go/inventory/v1/types.go index fb026a26..f3a5dcd1 100644 --- a/go/inventory/v1/types.go +++ b/go/inventory/v1/types.go @@ -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 { @@ -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) }