in reply to reordering lists
just because row 27,895 out of 500,000 was repositioned to slot 3, now 499,998 rows will have their id recalculated.Not so. Only the ones between the old and new positions need to be recalculated.
sub move { my ($from, $to) = @_; my $temp = $row[$from]; if ($from < $to) { for ($from+1..$to) { $row[$_-1] = $row[$_]; } } else { for (0..$from-$to-1) { $row[$from-$_] = $row[$from-$_-1]; } } $row[$to] = $temp; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: reordering lists
by punkish (Priest) on Jan 20, 2004 at 21:44 UTC |