/proc/self/cwd/external/re2~/re2/bitmap256.cc
Line | Count | Source |
1 | | // Copyright 2023 The RE2 Authors. All Rights Reserved. |
2 | | // Use of this source code is governed by a BSD-style |
3 | | // license that can be found in the LICENSE file. |
4 | | |
5 | | #include "re2/bitmap256.h" |
6 | | |
7 | | #include <stdint.h> |
8 | | |
9 | | #include "absl/log/absl_check.h" |
10 | | |
11 | | namespace re2 { |
12 | | |
13 | 0 | int Bitmap256::FindNextSetBit(int c) const { |
14 | 0 | ABSL_DCHECK_GE(c, 0); |
15 | 0 | ABSL_DCHECK_LE(c, 255); |
16 | | |
17 | | // Check the word that contains the bit. Mask out any lower bits. |
18 | 0 | int i = c / 64; |
19 | 0 | uint64_t word = words_[i] & (~uint64_t{0} << (c % 64)); |
20 | 0 | if (word != 0) |
21 | 0 | return (i * 64) + FindLSBSet(word); |
22 | | |
23 | | // Check any following words. |
24 | 0 | i++; |
25 | 0 | switch (i) { |
26 | 0 | case 1: |
27 | 0 | if (words_[1] != 0) |
28 | 0 | return (1 * 64) + FindLSBSet(words_[1]); |
29 | 0 | [[fallthrough]]; |
30 | 0 | case 2: |
31 | 0 | if (words_[2] != 0) |
32 | 0 | return (2 * 64) + FindLSBSet(words_[2]); |
33 | 0 | [[fallthrough]]; |
34 | 0 | case 3: |
35 | 0 | if (words_[3] != 0) |
36 | 0 | return (3 * 64) + FindLSBSet(words_[3]); |
37 | 0 | [[fallthrough]]; |
38 | 0 | default: |
39 | 0 | return -1; |
40 | 0 | } |
41 | 0 | } |
42 | | |
43 | | } // namespace re2 |