Exact Searching
The bitap algorithm for exact string searching, in full generality, looks like this when implemented in C:
#includeBitap distinguishes itself from other well-known string searching algorithms in its natural mapping onto simple bitwise operations, as in the following modification of the above program. Notice that in this implementation, counterintuitively, each bit with value zero indicates a match, and each bit with value 1 indicates a non-match. The same algorithm can be written with the intuitive semantics for 0 and 1, but in that case we must introduce another instruction into the inner loop to set R |= 1. In this implementation, we take advantage of the fact that left-shifting a value shifts in zeros on the right, which is precisely the behavior we need.
Notice also that we require CHAR_MAX additional bitmasks in order to convert the (text == pattern) condition in the general implementation into bitwise operations. Therefore, the bitap algorithm performs better when applied to inputs over smaller alphabets.
Read more about this topic: Bitap Algorithm
Famous quotes containing the words exact and/or searching:
“In the most desirable conditions, the child learns to manage anxiety by being exposed to just the right amounts of it, not much more and not much less. This optimal amount of anxiety varies with the childs age and temperament. It may also vary with cultural values.... There is no mathematical formula for calculating exact amounts of optimal anxiety. This is why child rearing is an art and not a science.”
—Alicia F. Lieberman (20th century)
“A government deriving its energy from the will of the society, and operating, by the reason of its measures, on the understanding and interest of the society ... is the government for which philosophy has been searching and humanity been fighting from the most remote ages ... which it is the glory of America to have invented, and her unrivalled happiness to possess.”
—James Madison (17511836)