-
Notifications
You must be signed in to change notification settings - Fork 919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regex cleanup internal reclass and reclass_device classes #11045
Regex cleanup internal reclass and reclass_device classes #11045
Conversation
Codecov Report
@@ Coverage Diff @@
## branch-22.08 #11045 +/- ##
===============================================
Coverage ? 86.34%
===============================================
Files ? 144
Lines ? 22729
Branches ? 0
===============================================
Hits ? 19625
Misses ? 3104
Partials ? 0 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of questions, but I like this cleanup overall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification and changes.
// transform pairs of literals to ranges | ||
std::vector<reclass_range> ranges(literals.size() / 2); | ||
auto const counter = thrust::make_counting_iterator(0); | ||
std::transform(counter, counter + ranges.size(), ranges.begin(), [&literals](auto idx) { | ||
return reclass_range{literals[idx * 2], literals[idx * 2 + 1]}; | ||
}); | ||
// sort the ranges to help with detecting overlapping entries | ||
std::sort(ranges.begin(), ranges.end(), [](auto l, auto r) { | ||
return l.first == r.first ? l.last < r.last : l.first < r.first; | ||
}); | ||
// combine overlapping entries: [a-f][c-g] => [a-g] | ||
if (ranges.size() > 1) { | ||
for (auto itr = ranges.begin() + 1; itr < ranges.end(); ++itr) { | ||
auto const prev = *(itr - 1); | ||
if (itr->first <= prev.last + 1) { | ||
// if these 2 ranges intersect, expand the current one | ||
*itr = reclass_range{prev.first, std::max(prev.last, itr->last)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is impressive. So much more readable.
cpp/src/strings/regex/regexec.cu
Outdated
@@ -104,14 +109,14 @@ std::unique_ptr<reprog_device, std::function<void(reprog_device*)>> reprog_devic | |||
auto d_end = d_ptr + (classes_count * sizeof(reclass_device)); | |||
// place each class and append the variable length data | |||
for (int32_t idx = 0; idx < classes_count; ++idx) { | |||
reclass& h_class = h_prog.class_at(idx); | |||
auto h_class = h_prog.class_at(idx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent the copying of literals
(as the previous code did), should this not be auto const& h_class = ...;
? Or is that affordable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct. Good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent! I really appreciate how the right abstraction makes the code so much more readable.
@gpucibot merge |
This cleans up the awkward range literals for supporting the
CCLASS
andNCCLASS
regex instructions. The range values were always paired (first,last) but arranged consecutively in a flat vector so[idx] and [idx+1]
were range pairsidx
was even. This PR introduces areclass_range
class that holds the pairs so we can use normal algorithms to manipulate them.There is some overlap with code changes in PR #10975
Reference #3582