The SFXC software correlator for very long baseline interferometry: algorithms and implementation