@Override
    public boolean apply(int[] perm) {
        for (MappedPairs mpair : mapped) {

            // possibly 'or' of query maps, need to use a set
            if (mpair.rIdxs.length > 1) {
                // bind target reactant maps
                final Set<Integer> bound = new HashSet<>();
                for (int rIdx : mpair.rIdxs) {
                    int refidx = mapidx(target.getAtom(perm[rIdx]));
                    if (refidx == 0) return false; // unmapped in target
                    bound.add(refidx);
                }

                // check product maps
                for (int pIdx : mpair.pIdxs) {
                    if (!bound.contains(mapidx(target.getAtom(perm[pIdx]))))
                        return false;
                }
            }
            // no 'or' of query atom map (more common case)
            else {
                final int refidx = mapidx(target.getAtom(perm[mpair.rIdxs[0]]));
                if (refidx == 0) return false; // unmapped in target
                // pairwise mismatch
                if (refidx != mapidx(target.getAtom(perm[mpair.pIdxs[0]])))
                    return false;
                for (int i = 1; i < mpair.pIdxs.length; i++) {
                    if (refidx != mapidx(target.getAtom(perm[mpair.pIdxs[i]])))
                        return false;
                }
            }


        }
        return true;
    }
@ Override public boolean apply ( int [ ] perm ) { for ( MappedPairs mpair : mapped ) { if ( mpair . rIdxs . length > 1 ) { final Set < Integer > bound = new HashSet < > ( ) ; for ( int rIdx : mpair . rIdxs ) { int refidx = mapidx ( target . getAtom ( perm [ rIdx ] ) ) ; if ( refidx == 0 ) return false ; bound . add ( refidx ) ; } for ( int pIdx : mpair . pIdxs ) { if ( ! bound . contains ( mapidx ( target . getAtom ( perm [ pIdx ] ) ) ) ) return false ; } } else { final int refidx = mapidx ( target . getAtom ( perm [ mpair . rIdxs [ 0 ] ] ) ) ; if ( refidx == 0 ) return false ; if ( refidx != mapidx ( target . getAtom ( perm [ mpair . pIdxs [ 0 ] ] ) ) ) return false ; for ( int i = 1 ; i < mpair . pIdxs . length ; i ++ ) { if ( refidx != mapidx ( target . getAtom ( perm [ mpair . pIdxs [ i ] ] ) ) ) return false ; } } } return true ; }
Filters a structure match (described as an index permutation query -> target) for
those where the atom-atom maps are acceptable.

@param perm permuation
@return whether the match should be accepted