private byte[] getIntersectionWithSortAndMergeAlgorithm(byte[] a, byte[] b) {
        // Take copies to not trample existing arrays.
        a = a.clone();
        b = b.clone();

        Arrays.sort(a);
        Arrays.sort(b);

        int ixA = 0;
        int ixB = 0;

        List<Byte> out = new ArrayList<>();

        while(ixA < a.length && ixB < b.length){
            if(a[ixA] == b[ixB]) {
                byte val = a[ixA];
                out.add(val);
                while(ixA < a.length && a[ixA] == val) {
                    ++ixA;
                }
                while(ixB < b.length && b[ixB] == val) {
                    ++ixB;
                }
                continue;
            }
            else if(a[ixA] < b[ixB]) {
                ++ixA;
            }
            else if(a[ixA] > b[ixB]) {
                ++ixB;
            }
            else {
                throw new AssertionError("This should not be reached.");
            }
        }
        
        return Bytes.toArray(out);
    }