Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^5: Date Array Convolution

by choroba (Cardinal)
on Nov 05, 2011 at 03:59 UTC ( [id://936091]=note: print w/replies, xml ) Need Help??


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

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://936091]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 22:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found