KevinStern / software-and-algorithms

Neat algorithm implementations in Java.
MIT License
118 stars 70 forks source link

added some short circuits to DamerauLevenshteinAlgorithm.execute() #1

Closed pschichtel closed 11 years ago

pschichtel commented 11 years ago

I added these short circuits to improve the performance and prevent a StringIndexOutOfBoundsException

KevinStern commented 11 years ago

Thank you for the contribution. I agree that zero length strings are not appropriately handled; though, I'm not convinced that the short circuit is an improvement since it imposes a cost on clients that will never compare equal strings. That being said, I'm on the fence with this cost argument, since your short circuit adds only a linear amount of work to a quadratic algorithm. At this point, I'd like to cherry-pick your zero-length string correction. Please let me know if you'd like to separate this out as a contribution to the code base, or if you'd like me to simply push the fix. I'll add a unit test for the zero-length string scenario, when it is fixed, regardless.

pschichtel commented 11 years ago

You may just push the fix.