libcds
libcds copied to clipboard
WaveletTreeNoptrs incorrectly assumes max element gets mapped to max element
Class WaveletTreeNoptrs allows me to specify a Mapper. I've implemented a custom mapper which maps most elements to 0 and a couple interesting ones to nonzero.
The constructor WaveletTreeNoptrs::WaveletTreeNoptrs(const Array & a, BitSequenceBuilder * bmb, Mapper * am) computes max_v = am->map(a.getMax()); and then sets height=bits(max_v);
When the maximum of the original values gets mapped to 0, the code sets the height of the tree to 0.
Perhaps I am missing the point but I suspect this is unintended?
I got the tree to work by changing the code to
max_v = 0;
for(size_t i = 0; i < n; i++){
symbols[i] = am->map(a[i]);
if( symbols[i] > max_v ) {
max_v = symbols[i];
}
}