factored out calculation of linear conflicts and inversions