| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c3aa3e7 commit fa376f4
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,17 +100,29 @@ class StringSearch : private StringSearchBase { | |||
| 100 | 100 | CHECK_GT(pattern_length, 0); | |
| 101 | 101 | if (pattern_length < kBMMinPatternLength) { | |
| 102 | 102 | if (pattern_length == 1) { | |
| 103 | - strategy_ = &StringSearch::SingleCharSearch; | ||
| 103 | + strategy_ = SearchStrategy::kSingleChar; | ||
| 104 | 104 | return; | |
| 105 | 105 | } | |
| 106 | - strategy_ = &StringSearch::LinearSearch; | ||
| 106 | + strategy_ = SearchStrategy::kLinear; | ||
| 107 | 107 | return; | |
| 108 | 108 | } | |
| 109 | - strategy_ = &StringSearch::InitialSearch; | ||
| 109 | + strategy_ = SearchStrategy::kInitial; | ||
| 110 | 110 | } | |
| 111 | 111 | ||
| 112 | 112 | size_t Search(Vector subject, size_t index) { | |
| 113 | - return (this->*strategy_)(subject, index); | ||
| 113 | + switch (strategy_) { | ||
| 114 | + case kBoyerMooreHorspool: | ||
| 115 | + return BoyerMooreHorspoolSearch(subject, index); | ||
| 116 | + case kBoyerMoore: | ||
| 117 | + return BoyerMooreSearch(subject, index); | ||
| 118 | + case kInitial: | ||
| 119 | + return InitialSearch(subject, index); | ||
| 120 | + case kLinear: | ||
| 121 | + return LinearSearch(subject, index); | ||
| 122 | + case kSingleChar: | ||
| 123 | + return SingleCharSearch(subject, index); | ||
| 124 | + } | ||
| 125 | + UNREACHABLE(); | ||
| 114 | 126 | } | |
| 115 | 127 | ||
| 116 | 128 | static inline int AlphabetSize() { | |
@@ -149,10 +161,17 @@ class StringSearch : private StringSearchBase { | |||
| 149 | 161 | return bad_char_occurrence[equiv_class]; | |
| 150 | 162 | } | |
| 151 | 163 | ||
| 164 | + enum SearchStrategy { | ||
| 165 | + kBoyerMooreHorspool, | ||
| 166 | + kBoyerMoore, | ||
| 167 | + kInitial, | ||
| 168 | + kLinear, | ||
| 169 | + kSingleChar, | ||
| 170 | + }; | ||
| 171 | + | ||
| 152 | 172 | // The pattern to search for. | |
| 153 | 173 | Vector pattern_; | |
| 154 | - // Pointer to implementation of the search. | ||
| 155 | - SearchFunction strategy_; | ||
| 174 | + SearchStrategy strategy_; | ||
| 156 | 175 | // Cache value of Max(0, pattern_length() - kBMMaxShift) | |
| 157 | 176 | size_t start_; | |
| 158 | 177 | }; | |
@@ -476,7 +495,7 @@ size_t StringSearch<Char>::BoyerMooreHorspoolSearch( | |||
| 476 | 495 | badness += (pattern_length - j) - last_char_shift; | |
| 477 | 496 | if (badness > 0) { | |
| 478 | 497 | PopulateBoyerMooreTable(); | |
| 479 | - strategy_ = &StringSearch::BoyerMooreSearch; | ||
| 498 | + strategy_ = SearchStrategy::kBoyerMoore; | ||
| 480 | 499 | return BoyerMooreSearch(subject, index); | |
| 481 | 500 | } | |
| 482 | 501 | } | |
@@ -548,7 +567,7 @@ size_t StringSearch<Char>::InitialSearch( | |||
| 548 | 567 | badness += j; | |
| 549 | 568 | } else { | |
| 550 | 569 | PopulateBoyerMooreHorspoolTable(); | |
| 551 | - strategy_ = &StringSearch::BoyerMooreHorspoolSearch; | ||
| 570 | + strategy_ = SearchStrategy::kBoyerMooreHorspool; | ||
| 552 | 571 | return BoyerMooreHorspoolSearch(subject, i); | |
| 553 | 572 | } | |
| 554 | 573 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments