MCPcopy Create free account
hub / github.com/chen3feng/toft / BuildLookupTable

Function BuildLookupTable

base/string/string_piece.cpp:156–163  ·  view source on GitHub ↗

For each character in characters_wanted, sets the index corresponding to the ASCII code of that character to 1 in table. This is used by the m_find.*_of methods below to tell whether or not a character is in the lookup table in constant time. The argument `table' must be an array that is large enough to hold all the possible values of an unsigned char. Thus it should be be declared as follows: b

Source from the content-addressed store, hash-verified

154// as follows:
155// bool table[UCHAR_MAX + 1]
156static inline void BuildLookupTable(const StringPiece& characters_wanted,
157 bool* table) {
158 const size_type length = characters_wanted.length();
159 const char* const data = characters_wanted.data();
160 for (size_type i = 0; i < length; ++i) {
161 table[static_cast<unsigned char>(data[i])] = true;
162 }
163}
164
165size_type StringPiece::find_first_of(const StringPiece& s,
166 size_type pos) const {

Callers 4

find_first_ofMethod · 0.85
find_first_not_ofMethod · 0.85
find_last_ofMethod · 0.85
find_last_not_ofMethod · 0.85

Calls 2

dataMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected