faster and more space-efficient implementation of WaveletTree