@@ -411,7 +411,6 @@ def closest_matching_file_function_name(
411411 closest_match = function
412412 closest_file = file_path
413413
414-
415414 if closest_match is not None and closest_file is not None :
416415 return closest_file , closest_match
417416 return None
@@ -949,87 +948,11 @@ def filter_files_optimized(file_path: Path, tests_root: Path, ignore_paths: list
949948 )
950949
951950
952-
953-
954-
955951def _bounded_levenshtein (s1 : str , s2 : str , max_distance : int ) -> int :
956952 """Compute Levenshtein distance but stop when distance exceeds max_distance.
957- Returns a value > max_distance when the true distance is > max_distance."""
958- # Fast path equal
959- if s1 == s2 :
960- return 0
961-
962- # Ensure s1 is the shorter
963- if len (s1 ) > len (s2 ):
964- s1 , s2 = s2 , s1
965-
966- n = len (s1 )
967- m = len (s2 )
968-
969- # If length difference already exceeds max allowed distance, we can exit
970- if m - n > max_distance :
971- return max_distance + 1
972-
973- # Initialize previous row: distances from empty s2 prefix to s1 prefixes
974- previous = list (range (n + 1 ))
975- current = [0 ] * (n + 1 )
976-
977- # We will only compute values within a "band" [start..end] for each row
978- for i in range (1 , m + 1 ):
979- # Position in s2 is i (1-based for DP), character is s2[i-1]
980- char2 = s2 [i - 1 ]
981- # Compute band boundaries (1-based indices for s1 positions)
982- start = max (1 , i - max_distance )
983- end = min (n , i + max_distance )
984-
985- # If start > end the band is empty -> distance exceeds max_distance
986- if start > end :
987- return max_distance + 1
988-
989- # Set current[0] for the empty prefix of s1
990- current [0 ] = i
991-
992- # Fill left part outside band with large values
993- for k in range (1 , start ):
994- current [k ] = max_distance + 1
995-
996- # Compute values inside the band
997- for j in range (start , end + 1 ):
998- if s1 [j - 1 ] == char2 :
999- current [j ] = previous [j - 1 ]
1000- else :
1001- # deletion = previous[j] + 1
1002- # insertion = current[j - 1] + 1
1003- # substitution = previous[j - 1] + 1
1004- a = previous [j ] + 1
1005- b = current [j - 1 ] + 1
1006- c = previous [j - 1 ] + 1
1007- # Fast min of three
1008- t = a if a < b else b
1009- current [j ] = c if c < t else t
1010-
1011- # Fill right part outside band with large values
1012- for k in range (end + 1 , n + 1 ):
1013- current [k ] = max_distance + 1
1014953
1015- # Swap rows
1016- previous , current = current , previous
1017-
1018- # Early exit: if the minimum value in the active band is greater than max_distance
1019- # then the final distance must exceed max_distance
1020- # (band width is small: at most 2*max_distance+1).
1021- row_min = min (previous [start : end + 1 ])
1022- if row_min > max_distance :
1023- return max_distance + 1
1024-
1025- return previous [n ]
1026-
1027-
1028-
1029-
1030- def _bounded_levenshtein (s1 : str , s2 : str , max_distance : int ) -> int :
1031- """Compute Levenshtein distance but stop when distance exceeds max_distance.
1032- Returns a value > max_distance when the true distance is > max_distance."""
954+ Returns a value > max_distance when the true distance is > max_distance.
955+ """
1033956 # Fast path equal
1034957 if s1 == s2 :
1035958 return 0
@@ -1080,8 +1003,8 @@ def _bounded_levenshtein(s1: str, s2: str, max_distance: int) -> int:
10801003 b = current [j - 1 ] + 1
10811004 c = previous [j - 1 ] + 1
10821005 # Fast min of three
1083- t = a if a < b else b
1084- current [j ] = c if c < t else t
1006+ t = min ( b , a )
1007+ current [j ] = min ( t , c )
10851008
10861009 # Fill right part outside band with large values
10871010 for k in range (end + 1 , n + 1 ):
0 commit comments