Skip to content

Instantly share code, notes, and snippets.

@rygorous
Last active September 23, 2015 06:03
Embed
What would you like to do?
Half-open interval overlap (mod N), fully symmetric
// 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