As the old joke goes: if I were setting out to get there, I wouldn't be starting from here!
Presumably you do not magically start out with these thousands of Set::IntSpan objects. You must be building them up from the log file(s)?
If so, it would be far more efficient to build up your required final representation, at the same time, (or in place of), as you are iterating the log and generating those objects. The logic is far simpler and falls out naturally from the ordered nature of the log:
my @timeSlots; my $concurrent = 0; my $lastTimeSlot = 0; while( <$log> ) { my( $time, $type ) = m[(...).+(Start|End)]; ++$concurrent if $type eq 'Start'; --$concurrent if $type eq 'End'; my $timeSlot = timeToTimeslot( $time ); push @timeSlots, ( $concurrent ) x ( $timeSlot - $lastTimeSlot ); $lastTimeSlot = $timeSlot; ## Do stuff to build your intspan objects ... }
By the time you've iterated the logs and generated the IntSpan objects, you already have your array of concurrency counts per timeslot for free.
In reply to Re: Efficient algorithm needed to split Set::IntSpan objects
by BrowserUk
in thread Efficient algorithm needed to split Set::IntSpan objects
by tim.bunce
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |