On Wed, 3 Mar 2004, Rick Measham wrote: > Currently if I have: > $this_year = span 2004-01-01 to 2004-12-31 > $today = span 2004-03-03 > > And I put them into a spanset, then all I can retrieve is a span > equivelent to $this_year.
I'm assuming by "put them into a spanset", you mean creating a set that is the union of the two. In this case, the union of the two sets is simply $this_year, because it contains $today completely. That is indeed the correct behavior. > However what I wanted to do was to be able to 'discover' that $now was > a part of both $this_year and $today. > > What I'm working on at the moment is not using spanset, but just a hash > of spans and spansets: > $calendar = { > 'sundays' => spanset of sundays, > 'today' => span of today, > 'this_year' => span of this year, > 'sunrise' => set of datetimes > } > > But then, when I throw $now at it, I have to loop over every element in > the hash looking for an intersection. That's probably the only way to do it. > So what I did next was to create a single spanset every time $calendar > was altered. That spanset is basically a merge of all elements of the > hash, so now I can just see if $now intersects $total_span_set. Right. > All this, however, takes time. Is there a better way to do all this? > What if I sort the hash by startdate and then binary search? Surely the > sort will take more time than a loop search. Well, how often do you need to sort, and how often do you need to search? That will determine which is faster. -dave /*======================= House Absolute Consulting www.houseabsolute.com =======================*/