Key indexed counting algorithm