public void filter()

in hollow/src/main/java/com/netflix/hollow/tools/diff/exact/DiffEqualOrdinalFilter.java [49:122]


    public void filter(IntList fromOrdinals, IntList toOrdinals) {
        matchedFromOrdinals.clear();
        matchedToOrdinals.clear();
        unmatchedFromOrdinals.clear();
        unmatchedToOrdinals.clear();

        int hashSize = 1 << (32 - Integer.numberOfLeadingZeros((fromOrdinals.size() * 2) - 1));
        if(hashedIdentityOrdinals.length < hashSize) {
            hashedIdentityOrdinals = new int[hashSize];
            hashedIdentityOrdinalsCounts = new int[hashSize];
            matchedOrdinalsCounts = new int[hashSize];
        }

        Arrays.fill(hashedIdentityOrdinals, -1);
        Arrays.fill(hashedIdentityOrdinalsCounts, 0);
        Arrays.fill(matchedOrdinalsCounts, 0);

        for(int i=0;i<fromOrdinals.size();i++) {
            int identity = equalOrdinalMap.getIdentityFromOrdinal(fromOrdinals.get(i));
            if(identity != -1) {
                int hashCode = HashCodes.hashInt(identity);
                int bucket = hashCode & (hashedIdentityOrdinals.length - 1);

                while(hashedIdentityOrdinals[bucket] != -1 && hashedIdentityOrdinals[bucket] != identity) {
                    bucket = (bucket + 1) & (hashedIdentityOrdinals.length - 1);
                }

                hashedIdentityOrdinals[bucket] = identity;
                hashedIdentityOrdinalsCounts[bucket]++;
            }
        }

        for(int i=0;i<toOrdinals.size();i++) {
            int identity = equalOrdinalMap.getIdentityToOrdinal(toOrdinals.get(i));
            if(identity != -1) {
                int hashCode = HashCodes.hashInt(identity);
                int bucket = hashCode & (hashedIdentityOrdinals.length - 1);

                while(hashedIdentityOrdinals[bucket] != -1 && hashedIdentityOrdinals[bucket] != identity) {
                    bucket = (bucket + 1) & (hashedIdentityOrdinals.length - 1);
                }

                if(hashedIdentityOrdinals[bucket] == identity && matchedOrdinalsCounts[bucket] < hashedIdentityOrdinalsCounts[bucket]) {
                    matchedOrdinalsCounts[bucket]++;
                    matchedToOrdinals.add(toOrdinals.get(i));
                } else {
                    unmatchedToOrdinals.add(toOrdinals.get(i));
                }
            } else {
                unmatchedToOrdinals.add(toOrdinals.get(i));
            }
        }

        for(int i=0;i<fromOrdinals.size();i++) {
            int identity = equalOrdinalMap.getIdentityFromOrdinal(fromOrdinals.get(i));
            if(identity != -1) {
                int hashCode = HashCodes.hashInt(identity);
                int bucket = hashCode & (hashedIdentityOrdinals.length - 1);

                while(hashedIdentityOrdinals[bucket] != identity) {
                    bucket = (bucket + 1) & (hashedIdentityOrdinals.length - 1);
                }

                if(matchedOrdinalsCounts[bucket] > 0) {
                    matchedOrdinalsCounts[bucket]--;
                    matchedFromOrdinals.add(fromOrdinals.get(i));
                } else {
                    unmatchedFromOrdinals.add(fromOrdinals.get(i));
                }
            } else {
                unmatchedFromOrdinals.add(fromOrdinals.get(i));
            }
        }
    }