X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FCpuSet.pm;fp=src%2FPVE%2FCpuSet.pm;h=4004bb3bab1a620f137068f279e03982447bf77e;hp=ef660b5c52ca04d2fe6fc2b5de6d905790ba4232;hb=284dca701b3461cd41efe52c1c395a9a7a42095b;hpb=2862235726cd0252e092460cf50e6e56906be31f diff --git a/src/PVE/CpuSet.pm b/src/PVE/CpuSet.pm index ef660b5..4004bb3 100644 --- a/src/PVE/CpuSet.pm +++ b/src/PVE/CpuSet.pm @@ -136,4 +136,35 @@ sub is_equal { return 1; } +sub short_string { + my ($self) = @_; + + my @members = $self->members(); + + my $res = ''; + my ($last, $next); + foreach my $cpu (@members) { + if (!defined($last)) { + $last = $next = $cpu; + } elsif (($next + 1) == $cpu) { + $next = $cpu; + } else { + $res .= ',' if length($res); + $res .= "$last-$next"; + $last = $next = undef; + } + } + + if (defined($last)) { + $res .= ',' if length($res); + if ($last != $next) { + $res .= "$last-$next"; + } else { + $res .= "$last"; + } + } + + return $res; +} + 1;