Skip to content

Instantly share code, notes, and snippets.

@lemire
Created March 5, 2014 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemire/9378174 to your computer and use it in GitHub Desktop.
Save lemire/9378174 to your computer and use it in GitHub Desktop.
size_t
compute_intersection (const uint32_t * rare,
const size_t nrare, const uint32_t * freq, const size_t nfreq, uint32_t * out) {
UINT4 goal;
const UINT4 *stop_rare;
UINT4 *init_out;
long j;
long nfreqleft = static_cast<int>(nfreq);// possibly unsafe if nfreq exceeds the range of longs
init_out = out;
stop_rare = &(rare[nrare]);
while (rare < stop_rare) {
goal = *rare++;
j = FINDFUNCTION(goal,freq,nfreqleft);
if (j >= nfreqleft) {
return (out - init_out);
} else if (freq[j] == goal) {
*out++ = goal;
}
freq += j;
nfreqleft -= j;
}
return (out - init_out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment