Half-open interval overlap (mod N), fully symmetric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // do [a,b) and [c,d) overlap? | |
| // (assumes N <= INT_MAX/2) | |
| static bool half_open_intervals_overlap(int a, int b, int c, int d) | |
| { | |
| int w0 = modN(b - a); | |
| int w1 = modN(d - c); | |
| return (w1 && modN(c - a) < w0) || (w0 && modN(a - c) < w1); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment