Re: SpanSet Issues and Requests
Rick Measham wrote: I'm trying to get next/previous spans from a given DateTime. I'm defining next/previous as the event who started before or after $dt. Where it ends doesn't matter, even if we're still in the middle of the event. Rick: Did you get it working? I'm starting the implementation of DateTime::SpanSet next/previous. I'll use these definitions: next - first span of $set-intersection( DT::Span-from_datetimes( after = $dt ) ) previous - last span of $set-intersection( DT::Span-from_datetimes( before = $dt ) ) - Flavio S. Glock
SpanSet Issues and Requests
G'day Flavio, I'm doing some intensive SpanSet stuff and I'm thinking you might be able to answer a couple of questions: I'm trying to get next/previous spans from a given DateTime. I'm defining next/previous as the event who started before or after $dt. Where it ends doesn't matter, even if we're still in the middle of the event. To get the 'next' I'm intersecting with a span starting at $dt and ending at +inf. Then I get $iterator-next. I return it unless the spanset contains $dt. If it does then I return $iterator-next. This seems a lot to do to get the next span after a particular $dt. However, to get the previous is even worse! Once again I intersect with -inf to $dt. Then if the spanset contains $dt, I get the max of the complement of the intersection. This is the start of the span I want. Now to get then end of it, I can't see any other way than to intersect the original span with $dt to +inf. Which seems like craziness to me! If we're not in the middle of a span, it goes on! First I get the max of the -inf to $dt spanset intersection. That's the end of the span I want, lets call that $dt2. I then get the max of the complement of -inf to $dt2, that's the start of the span. All the above takes time. Seconds in fact! Surely there's a better way ... I'd really like to have $spanset-next_span($dt) and $spanset-previous_span($dt) but if there's some way to do it myself that is better than what I'm doing I'd love to know. Thanks and Cheers! Rick Measham
Re: SpanSet Issues and Requests
On Thu, 9 Oct 2003, Flavio S. Glock wrote: DT::SpanSet misses all these methods: next( $dt ) previous( $dt ) current( $dt ) closest( $dt ) as_list Is it ok to implement this in DT::SpanSet? Please do! /*=== House Absolute Consulting www.houseabsolute.com ===*/
Re: SpanSet Issues and Requests
I've done some diagrams, in order to check if you agree with the semantics of these SpanSet functions. Some of these operations can be interpreted in more than one way. If you think something should be different, please let me know. This is the notation used: [aaa] - a closed spanset or span (aaa) - an open set [aaa) - semi-open set ()- empty set dt- a datetime object --- next( $dt ) given: [ aa bb ] ^dt returns: [bb] given: [ aaabbb ] ^dt returns: [aaabbb] could also be: (bbb] given: [ aaa ] ^dt returns:() --- previous( $dt ) given: [ aa bb ] ^dt returns: [aa] given: [ aaabbb ] ^dt returns: [aaabbb] could also be: [aaa) given: [ aaa ] ^dt returns:() --- current( $dt ) given: [ aa bb ] ^dt returns: [aa] given: [ aaabbb ] ^dt returns: [aaabbb] could also be: dt given: [ aaa ] ^dt returns:() given: [ aaa ] ^dt returns: [aaa] --- closest( $dt ) given: [ aa bb ] ^dt returns: [aa] given: [ aa ] ^dt returns: [aa] could also be: dt --- as_list given: [ aa bb ] returns: [aa],[bb] --- - Flavio S. Glock