How about a brute force space-for-time tradeoff?
A 3.8Mb bitmap can represent an entire year's worth of seconds. Allocate and clear the bitmap, then turn on bits for second within intervals. The probe to determine whether a given time occurs within at least one interval is O(1).
This merges intervals, so it's not useful if you're trying to determine which intervals a given time occurs within. A tree structure is more appropriate for that.
"It's not the Zen way, but it gets the job done." --Garrison Keillor
In reply to Re: Assemble times into ranges
by dws
in thread Assemble times into ranges
by Dominus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |