Efficient residue comparison algorithm for general moduli sets