@@ -2030,7 +2030,7 @@ class basic_string_slice {
20302030 * * `replace`, `insert`, `erase`, `append`, `push_back`, `pop_back`, `resize`, `shrink_to_fit`... from STL,
20312031 * * `try_` exception-free "try" operations that returning non-zero values on success,
20322032 * * `replace_all` and `erase_all` similar to Boost,
2033- * * `edit_distance ` - Levenshtein distance computation reusing the allocator,
2033+ * * `levenshtein_distance ` - Levenshtein distance computation reusing the allocator,
20342034 * * `translate` - character mapping,
20352035 * * `randomize`, `random` - for fast random string generation.
20362036 *
@@ -3360,11 +3360,12 @@ class basic_string {
33603360
33613361 concatenation<string_view, string_view> operator |(string_view other) const noexcept { return {view (), other}; }
33623362
3363- size_type edit_distance (string_view other, size_type bound = 0 ) const noexcept {
3364- size_type result;
3365- _with_alloc ([&](sz_alloc_type &alloc) {
3363+ size_type levenshtein_distance (string_view other, size_type bound = std::numeric_limits<size_type>::max()) const
3364+ noexcept (false ) {
3365+ size_type result = std::numeric_limits<size_type>::max ();
3366+ raise (_with_alloc ([&](sz_alloc_type &alloc) {
33663367 return sz_levenshtein_distance (data (), size (), other.data (), other.size (), bound, &alloc, &result);
3367- });
3368+ })) ;
33683369 return result;
33693370 }
33703371
@@ -3839,7 +3840,7 @@ typename concatenation_result<first_type, second_type, following_types...>::type
38393840template <typename char_type_>
38403841std::size_t hamming_distance ( //
38413842 basic_string_slice<char_type_> const &a, basic_string_slice<char_type_> const &b, //
3842- std::size_t bound = 0 ) noexcept {
3843+ std::size_t bound = SZ_SIZE_MAX ) noexcept {
38433844 std::size_t result;
38443845 sz_hamming_distance (a.data (), a.size (), b.data (), b.size (), bound, &result);
38453846 return result;
@@ -3852,7 +3853,7 @@ std::size_t hamming_distance(
38523853template <typename char_type_, typename allocator_type_ = std::allocator<typename std::remove_const<char_type_>::type>>
38533854std::size_t hamming_distance ( //
38543855 basic_string<char_type_, allocator_type_> const &a, basic_string<char_type_, allocator_type_> const &b, //
3855- std::size_t bound = 0 ) noexcept {
3856+ std::size_t bound = SZ_SIZE_MAX ) noexcept {
38563857 return ashvardanian::stringzilla::hamming_distance (a.view (), b.view (), bound);
38573858}
38583859
@@ -3862,7 +3863,8 @@ std::size_t hamming_distance(
38623863 */
38633864template <typename char_type_>
38643865std::size_t hamming_distance_utf8 ( //
3865- basic_string_slice<char_type_> const &a, basic_string_slice<char_type_> const &b, std::size_t bound = 0 ) noexcept {
3866+ basic_string_slice<char_type_> const &a, basic_string_slice<char_type_> const &b,
3867+ std::size_t bound = SZ_SIZE_MAX) noexcept {
38663868 std::size_t result;
38673869 sz_hamming_distance_utf8 (a.data (), a.size (), b.data (), b.size (), bound, &result);
38683870 return result;
@@ -3875,7 +3877,7 @@ std::size_t hamming_distance_utf8( //
38753877template <typename char_type_, typename allocator_type_ = std::allocator<typename std::remove_const<char_type_>::type>>
38763878std::size_t hamming_distance_utf8 ( //
38773879 basic_string<char_type_, allocator_type_> const &a, basic_string<char_type_, allocator_type_> const &b,
3878- std::size_t bound = 0 ) noexcept {
3880+ std::size_t bound = SZ_SIZE_MAX ) noexcept {
38793881 return ashvardanian::stringzilla::hamming_distance_utf8 (a.view (), b.view (), bound);
38803882}
38813883
@@ -3884,10 +3886,10 @@ std::size_t hamming_distance_utf8( //
38843886 * @sa sz_levenshtein_distance
38853887 */
38863888template <typename char_type_, typename allocator_type_ = std::allocator<typename std::remove_const<char_type_>::type>>
3887- std::size_t edit_distance ( //
3889+ std::size_t levenshtein_distance ( //
38883890 basic_string_slice<char_type_> const &a, basic_string_slice<char_type_> const &b, std::size_t bound = SZ_SIZE_MAX,
38893891 allocator_type_ &&allocator = allocator_type_ {}) noexcept (false ) {
3890- std::size_t result;
3892+ std::size_t result = SZ_SIZE_MAX ;
38913893 raise (_with_alloc (allocator, [&](sz_memory_allocator_t &alloc) {
38923894 return sz_levenshtein_distance (a.data (), a.size (), b.data (), b.size (), bound, &alloc, &result);
38933895 }));
@@ -3899,21 +3901,21 @@ std::size_t edit_distance( //
38993901 * @sa sz_levenshtein_distance
39003902 */
39013903template <typename char_type_, typename allocator_type_ = std::allocator<char_type_>>
3902- std::size_t edit_distance ( //
3904+ std::size_t levenshtein_distance ( //
39033905 basic_string<char_type_, allocator_type_> const &a, basic_string<char_type_, allocator_type_> const &b, //
39043906 std::size_t bound = SZ_SIZE_MAX) noexcept (false ) {
3905- return ashvardanian::stringzilla::edit_distance (a.view (), b.view (), bound, a.get_allocator ());
3907+ return ashvardanian::stringzilla::levenshtein_distance (a.view (), b.view (), bound, a.get_allocator ());
39063908}
39073909
39083910/* *
39093911 * @brief Calculates the Levenshtein edit distance in @b unicode codepoints between two strings.
39103912 * @sa sz_levenshtein_distance_utf8
39113913 */
39123914template <typename char_type_, typename allocator_type_ = std::allocator<typename std::remove_const<char_type_>::type>>
3913- std::size_t edit_distance_utf8 ( //
3915+ std::size_t levenshtein_distance_utf8 ( //
39143916 basic_string_slice<char_type_> const &a, basic_string_slice<char_type_> const &b, //
39153917 std::size_t bound = SZ_SIZE_MAX, allocator_type_ &&allocator = allocator_type_ {}) noexcept (false ) {
3916- std::size_t result;
3918+ std::size_t result = SZ_SIZE_MAX ;
39173919 raise (_with_alloc (allocator, [&](sz_memory_allocator_t &alloc) {
39183920 return sz_levenshtein_distance_utf8 (a.data (), a.size (), b.data (), b.size (), bound, &alloc, &result);
39193921 }));
@@ -3925,10 +3927,10 @@ std::size_t edit_distance_utf8(
39253927 * @sa sz_levenshtein_distance_utf8
39263928 */
39273929template <typename char_type_, typename allocator_type_ = std::allocator<char_type_>>
3928- std::size_t edit_distance_utf8 ( //
3930+ std::size_t levenshtein_distance_utf8 ( //
39293931 basic_string<char_type_, allocator_type_> const &a, basic_string<char_type_, allocator_type_> const &b, //
39303932 std::size_t bound = SZ_SIZE_MAX) noexcept (false ) {
3931- return ashvardanian::stringzilla::edit_distance_utf8 (a.view (), b.view (), bound, a.get_allocator ());
3933+ return ashvardanian::stringzilla::levenshtein_distance_utf8 (a.view (), b.view (), bound, a.get_allocator ());
39323934}
39333935
39343936/* *
@@ -3945,7 +3947,7 @@ std::ptrdiff_t alignment_score(
39453947 static_assert (std::is_signed<sz_error_cost_t >() == std::is_signed<std::int8_t >(),
39463948 " sz_error_cost_t must be signed." );
39473949
3948- std::ptrdiff_t result;
3950+ std::ptrdiff_t result = SZ_SSIZE_MIN ;
39493951 raise (_with_alloc (allocator, [&](sz_memory_allocator_t &alloc) {
39503952 return sz_needleman_wunsch_score (a.data (), a.size (), b.data (), b.size (), &subs[0 ][0 ], gap, &alloc, &result);
39513953 }));
0 commit comments