in reply to Can I speed this up? (repetitively scanning ranges in a large array)

What I currently do is to initialize a results array of size max_length (i.e. 4M) to zeros.

Then, for each range (start, end) I iterate over all coordinates i in (start,end).

I take min(i-start,end-i) (i.e. the distance to the nearest end of the range) and update results(i) with it if this val is larger.

I can't reproduce your results for your 3-ranges max-10 example by following those steps? I get 0 1 1 2 2 1 0 0 0 0.

So I think you really will have to post code.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^2: Can I speed this up?
by daverave (Scribe) on Nov 01, 2010 at 18:14 UTC
    I updated the original post.