Implement wavelet tree builder.