FAST-PT II: an algorithm to calculate convolution integrals of general tensor quantities in cosmological perturbation theory