Maps (usually) are implemented using red-black trees, which give an O (log N) search, since the tree is constantly in equilibrium. Your linear list of if statements will be the worst case of O (N). So, yes, the map will be significantly faster to search.
switch, , if. , , O (1), , undefined; . switch C ++.
, , , , ( I/ , 99% 1 ):
unsigned char single_bit_index(unsigned char bit) {
if(bit > 0x08)
if(bit > 0x20)
if(bit == 0x40)
return 6;
else
return 7;
else
if(bit == 0x10)
return 4;
else
return 5;
else
if(bit > 0x02)
if(bit == 0x04)
return 2;
else
return 3;
else
if(bit == 0x01)
return 0;
else
return 1;
}
3 8 , , - - 4- , 1 - 8 .
, , , , 8 , , : 1, 2, 4, 8, 16, 32, 64 128. 128 , 8 , , , .