Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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).


In reply to Re^5: Date Array Convolution by choroba
in thread Date Array Convolution by alanonymous

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-20 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found