Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Efficient algorithm needed to split Set::IntSpan objects (merge sort)

by tye (Sage)
on Sep 23, 2009 at 14:46 UTC ( [id://796988]=note: print w/replies, xml ) Need Help??


in reply to Efficient algorithm needed to split Set::IntSpan objects

Construct the sorted list of starting points and the sorted list of ending points. Do a "merge sort" on the two resulting sets but increment a count when selecting a starting number and decrement it when selecting an ending number. Track the last number selected and the count. If the new number doesn't match the previous number, then store the previous number and count. When you are done you'll have a list of starting numbers and counts. If you end up with consecutive identical counts, then you can drop all but the first of that run. Now you've got the starting number of each span and the number of repeats for that span (and a terminating end number with a count of 0).

Update: The "ending number" needs to be the first number not in the span. So an int span is defined by "$i where $start <= $i < $end".

- tye        

  • Comment on Re: Efficient algorithm needed to split Set::IntSpan objects (merge sort)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://796988]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-23 21:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found