basic suffix array builder with secondary sorting