Skip to content

Commit 0151750

Browse files
committed
fix some bugs in cleanup
1 parent 30628d3 commit 0151750

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

extras/rapidfuzz_amalgamated.hpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
22
// SPDX-License-Identifier: MIT
33
// RapidFuzz v1.0.2
4-
// Generated: 2023-12-24 17:28:29.475831
4+
// Generated: 2023-12-24 18:34:14.416744
55
// ----------------------------------------------------------
66
// This file is an amalgamation of multiple different files.
77
// You probably shouldn't edit it directly.
@@ -483,6 +483,9 @@ class Range {
483483
_size = static_cast<size_t>(std::distance(_first, _last));
484484
}
485485

486+
constexpr Range(Iter first, Iter last, size_t size) : _first(first), _last(last), _size(size)
487+
{}
488+
486489
template <typename T>
487490
constexpr Range(T& x) : _first(to_begin(x)), _last(to_end(x))
488491
{
@@ -513,11 +516,6 @@ class Range {
513516
return _size;
514517
}
515518

516-
constexpr ssize_t ssize() const
517-
{
518-
return static_cast<ssize_t>(_size);
519-
}
520-
521519
constexpr bool empty() const
522520
{
523521
return size() == 0;
@@ -544,6 +542,8 @@ class Range {
544542
else
545543
for (size_t i = 0; i < n; ++i)
546544
_first++;
545+
546+
_size -= n;
547547
}
548548
constexpr void remove_suffix(size_t n)
549549
{
@@ -553,17 +553,19 @@ class Range {
553553
else
554554
for (size_t i = 0; i < n; ++i)
555555
_last--;
556+
557+
_size -= n;
556558
}
557559

558560
constexpr Range subseq(size_t pos = 0, size_t count = std::numeric_limits<size_t>::max())
559561
{
560562
if (pos > size()) throw std::out_of_range("Index out of range in Range::substr");
561563

562-
// todo we should probably support non random access iterators here too
563-
ptrdiff_t scount = static_cast<ptrdiff_t>(count);
564-
auto start = _first + static_cast<ptrdiff_t>(pos);
565-
if (std::distance(start, _last) < scount) return {start, _last};
566-
return {start, start + scount};
564+
Range res = *this;
565+
res.remove_prefix(pos);
566+
if (count < res.size()) res.remove_suffix(res.size() - count);
567+
568+
return res;
567569
}
568570

569571
constexpr decltype(auto) front() const
@@ -578,7 +580,7 @@ class Range {
578580

579581
constexpr Range<reverse_iterator> reversed() const
580582
{
581-
return {rbegin(), rend()};
583+
return {rbegin(), rend(), _size};
582584
}
583585

584586
friend std::ostream& operator<<(std::ostream& os, const Range& seq)
@@ -7016,7 +7018,7 @@ void levenshtein_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatte
70167018
else {
70177019
if constexpr (!std::is_same_v<VecType, uint64_t>) {
70187020
size_t min_dist = abs_diff(s1_lengths[result_index], s2.size());
7019-
size_t wraparound_score = std::numeric_limits<VecType>::max() + 1;
7021+
size_t wraparound_score = static_cast<size_t>(std::numeric_limits<VecType>::max()) + 1;
70207022

70217023
score = (min_dist / wraparound_score) * wraparound_score;
70227024
VecType remainder = static_cast<VecType>(min_dist % wraparound_score);
@@ -8487,7 +8489,7 @@ void osa_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatternMatchV
84878489
else {
84888490
if constexpr (!std::is_same_v<VecType, uint64_t>) {
84898491
size_t min_dist = abs_diff(s1_lengths[result_index], s2.size());
8490-
size_t wraparound_score = std::numeric_limits<VecType>::max() + 1;
8492+
size_t wraparound_score = static_cast<size_t>(std::numeric_limits<VecType>::max()) + 1;
84918493

84928494
score = (min_dist / wraparound_score) * wraparound_score;
84938495
VecType remainder = static_cast<VecType>(min_dist % wraparound_score);

rapidfuzz/details/Range.hpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ class Range {
7575
_size = static_cast<size_t>(std::distance(_first, _last));
7676
}
7777

78+
constexpr Range(Iter first, Iter last, size_t size) : _first(first), _last(last), _size(size)
79+
{
80+
}
81+
7882
template <typename T>
7983
constexpr Range(T& x) : _first(to_begin(x)), _last(to_end(x))
8084
{
@@ -105,11 +109,6 @@ class Range {
105109
return _size;
106110
}
107111

108-
constexpr ssize_t ssize() const
109-
{
110-
return static_cast<ssize_t>(_size);
111-
}
112-
113112
constexpr bool empty() const
114113
{
115114
return size() == 0;
@@ -136,6 +135,8 @@ class Range {
136135
else
137136
for (size_t i = 0; i < n; ++i)
138137
_first++;
138+
139+
_size -= n;
139140
}
140141
constexpr void remove_suffix(size_t n)
141142
{
@@ -145,17 +146,20 @@ class Range {
145146
else
146147
for (size_t i = 0; i < n; ++i)
147148
_last--;
149+
150+
_size -= n;
148151
}
149152

150153
constexpr Range subseq(size_t pos = 0, size_t count = std::numeric_limits<size_t>::max())
151154
{
152155
if (pos > size()) throw std::out_of_range("Index out of range in Range::substr");
153156

154-
// todo we should probably support non random access iterators here too
155-
ptrdiff_t scount = static_cast<ptrdiff_t>(count);
156-
auto start = _first + static_cast<ptrdiff_t>(pos);
157-
if (std::distance(start, _last) < scount) return {start, _last};
158-
return {start, start + scount};
157+
Range res = *this;
158+
res.remove_prefix(pos);
159+
if(count < res.size())
160+
res.remove_suffix(res.size() - count);
161+
162+
return res;
159163
}
160164

161165
constexpr decltype(auto) front() const
@@ -170,7 +174,7 @@ class Range {
170174

171175
constexpr Range<reverse_iterator> reversed() const
172176
{
173-
return {rbegin(), rend()};
177+
return {rbegin(), rend(), _size};
174178
}
175179

176180
friend std::ostream& operator<<(std::ostream& os, const Range& seq)

rapidfuzz/distance/Levenshtein_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void levenshtein_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatte
369369
else {
370370
if constexpr (!std::is_same_v<VecType, uint64_t>) {
371371
size_t min_dist = abs_diff(s1_lengths[result_index], s2.size());
372-
size_t wraparound_score = std::numeric_limits<VecType>::max() + 1;
372+
size_t wraparound_score = static_cast<size_t>(std::numeric_limits<VecType>::max()) + 1;
373373

374374
score = (min_dist / wraparound_score) * wraparound_score;
375375
VecType remainder = static_cast<VecType>(min_dist % wraparound_score);

rapidfuzz/distance/OSA_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void osa_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatternMatchV
153153
else {
154154
if constexpr (!std::is_same_v<VecType, uint64_t>) {
155155
size_t min_dist = abs_diff(s1_lengths[result_index], s2.size());
156-
size_t wraparound_score = std::numeric_limits<VecType>::max() + 1;
156+
size_t wraparound_score = static_cast<size_t>(std::numeric_limits<VecType>::max()) + 1;
157157

158158
score = (min_dist / wraparound_score) * wraparound_score;
159159
VecType remainder = static_cast<VecType>(min_dist % wraparound_score);

0 commit comments

Comments
 (0)