From efb2d6488091e64041141a5e5e902d67403499d7 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 31 Oct 2011 17:05:10 +0100 Subject: [PATCH] bprun: Recycle slots --- bprun | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/bprun b/bprun index b75a7fe..65dd089 100755 --- a/bprun +++ b/bprun @@ -123,24 +123,37 @@ sub done($) sub get_slot($) { my ($mach) = @_; - if (defined $by_host{$mach}) { - return $by_host{$mach}; + my $s; + if (defined ($s = $by_host{$mach})) { + delete $s->{'Gone'}; + } else { + my ($best, $besti); + for my $i (0..$nrows-1) { + my $r = $by_row[$i]; + if (!defined $r) { + $besti = $i; + $best = undef; + last; + } elsif ($r->{'Gone'} && (!$best || $best->{'Gone'} > $r->{'Gone'})) { + $besti = $i; + $best = $r; + } + } + if ($best) { + delete $by_host{$best->{'Host'}}; + } + $s->{'Host'} = $mach; + $s->{'Row'} = $besti; + $by_host{$mach} = $s; + $by_row[$besti] = $s; } - my $s = { - 'Host' => $mach, - }; - my $i = 0; - while (defined $by_row[$i]) { $i++; } - $s->{'Row'} = $i; - $by_row[$i] = $s; - $by_host{$mach} = $s; return $s; } +my $gone_counter = 1; sub delete_slot($) { my ($s) = @_; - delete $by_host{$s->{'Host'}}; - $by_row[$s->{'Row'}] = undef; + $s->{'Gone'} = $gone_counter++; } sub redraw_slot($) { -- 2.39.5