fclaude / libcds

Compact Data Structures Library
http://libcds.recoded.cl
GNU Lesser General Public License v2.1
124 stars 24 forks source link

WaveletTreeNoptrs incorrectly assumes max element gets mapped to max element #9

Open fdlk opened 11 years ago

fdlk commented 11 years ago

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?

fdlk commented 11 years ago

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];
    }
}