Determine if a character C is in a string str, what would you do with it? 1.for or while loop can be judged, but the efficiency is 2. Create a static mapping table of size 256 char tb[256], map all the values in the string str to TB, and judge Tb[c]==1 to know if the character exists in Str. Yes, or can be optimized for 3. TB is optimized with bit compression, since each char has 8 bits, the table can be compressed into char TB[256/8]; First compressed str to TB do{tb[*str >> 3] |= 1 << (*str & 7)}while (* (++STR)); What does this code mean? *str >> 3 Right shift three bits equals *str/81 << (*str & 7) to find the value of the last three bits of STR, after bit displacement 0-7 of the value corresponding to the 1-8bit operation is complete, TB each word nonspacing represents 8 characters to be verified, That is, each bit of the character in the TB represents one character of ASCII. Determine if the target bit has been flagged, and C is present in TB. if (Tb[c >> 3] & 1 << (C & 7)) The process of calculation is the same as the compression process, Tb[c >> 3] calculates the corresponding character, 1 << (C & 7) to find out which of the corresponding characters , the two bits are marked with the compressed character. The memory footprint is further optimized through bit operations. 2 and 3 methods have advantages and disadvantages, combined with the scene is very easy to tell which method to use. --Just upgraded the WIN10, all the browser to open the blog Garden Edit Control has an exception, only with IE can edit, but the format is also abnormal, and so normal and then modify the layout.
A bit compression technique