I'm looking for an algorithm that returns (the length of) the intersection of two given N^4 lists / sets (more precisely in [|0;7|]^4). I'm not expecting an answer in a specific programming language (I'm doing it in OCaml but as this language isn't very popular I don't expect answers to be written in Caml...). Note that solutions involving big pre-computations (for example to completly change the structure of sets) aren't a problem in my case.
I tried to consider N^4 sets as classical integer sets to then intersect them using buit-in set intersections (but this was way too slow for my purpose) and I also tried to consider them as N^2 sets to apply the Lebesgue fast N^2 intersect (this could have worked but it turns out points don't rearrange very randomly over the plane thus making this algorithm quite inefficient).