mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	suggestions.c: Improve efficiency of levenshtein_distance method (#91835)
This commit is contained in:
		
							parent
							
								
									341689cb85
								
							
						
					
					
						commit
						feb45d0ae9
					
				
					 1 changed files with 3 additions and 1 deletions
				
			
		|  | @ -78,9 +78,11 @@ levenshtein_distance(const char *a, size_t a_size, | |||
|     // Instead of producing the whole traditional len(a)-by-len(b)
 | ||||
|     // matrix, we can update just one row in place.
 | ||||
|     // Initialize the buffer row
 | ||||
|     size_t tmp = MOVE_COST; | ||||
|     for (size_t i = 0; i < a_size; i++) { | ||||
|         // cost from b[:0] to a[:i+1]
 | ||||
|         buffer[i] = (i + 1) * MOVE_COST; | ||||
|         buffer[i] = tmp; | ||||
|         tmp += MOVE_COST; | ||||
|     } | ||||
| 
 | ||||
|     size_t result = 0; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Pieter Eendebak
						Pieter Eendebak