proxygen
RangeCommon.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include <bitset>
20 
22 
23 namespace folly {
24 
25 namespace detail {
26 
28  const StringPieceLite haystack,
29  const StringPieceLite needles) {
30  std::bitset<256> s;
31  for (auto needle : needles) {
32  s[(uint8_t)needle] = true;
33  }
34  for (size_t index = 0; index < haystack.size(); ++index) {
35  if (s[(uint8_t)haystack[index]]) {
36  return index;
37  }
38  }
39  return std::string::npos;
40 }
41 
43  const StringPieceLite haystack,
44  const StringPieceLite needles) {
46  for (auto needle : needles) {
47  s.add(uint8_t(needle));
48  }
49  for (size_t index = 0; index < haystack.size(); ++index) {
50  if (s.contains(uint8_t(haystack[index]))) {
51  return index;
52  }
53  }
54  return std::string::npos;
55 }
56 } // namespace detail
57 } // namespace folly
const string needle
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:42
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
bool add(uint8_t i)
Definition: SparseByteSet.h:61
bool contains(uint8_t i) const
Definition: SparseByteSet.h:77
static set< string > s
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:27