Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Date Array Convolution

by alanonymous (Sexton)
on Nov 05, 2011 at 03:30 UTC ( #936087=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Date Array Convolution
in thread Date Array Convolution

You *Sir* are also a gentleman AND a scholar! I think the output is right, but I'm having trouble understanding exactly what's going on in your code. Like I mentioned to Mr. UK, you guys are awesome at coming up with solutions, but it's hard for newbies to understand it all! I *hate* taking code without understanding it :/


Comment on Re^4: Date Array Convolution
Re^5: Date Array Convolution
by choroba (Abbot) on Nov 05, 2011 at 03:59 UTC
    I'll try to explain my code:
    The new method just creates an empty object. The object is then populated by the populate method: it just remembers all the start end end points of all the intervals in times subhash. At each interval, it also remembers what value begins to be valid (push) or ceases to (pop).

    The most important method is combine. It sorts all the time points and then walks through them, keeping track of all "active" values for the given interval (the active values are stored in @stack). All the values whose intervals start at the given point are inserted into the stack, all values whose intervals end at the given point are popped. The grep { not defined $value or $_ != $value or undef $value } construct just makes sure repeated values are removed one by one from the stack. Then, if there is no value left, the current output interval is closed and stored in @result. If there was no value before, but now there is, a new interval is started. If the value has changed, the interval is closed and a new one is opened.

    Finally, the _day_split function is called on the result. It just examines each interval, and if it spans over several days, it splits it into several intervals. The first and last days are special, because their starting, resp. ending times are derived from the interval.

    The _dec and _inc are just helper functions to subtract or add 1 to a time stamp. They are needed to avoid "overlapping" of intervals, i.e. in

    1 7 |-----| (4) |--------| (3) 4 12
    the first interval will end at 3, which is _dec(4).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-10-02 10:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (52 votes), past polls