Fast O(N) calculations of genetic diversities and their variances