Optimizing Jaro-Winkler algorithm

前端 未结 6 2131
孤独总比滥情好
孤独总比滥情好 2021-02-05 13:45

I have this code for Jaro-Winkler algorithm taken from this website. I need to run 150,000 times to get distance between differences. It takes a long time, as I run on an Androi

6条回答
  •  没有蜡笔的小新
    2021-02-05 14:09

    1. Try to avoid the two nested loops in the getCommonCharacters loop.
      Suggestion as to how: store all the chars in the smaller string in a map of some sort(java has a few), where the key is the character and the value is the position, that way you can still calculate the distance, wether they are in common. I don't quite understand the algorithm, but I think this is doable.
    2. Except for that and bmargulies's answer, I really don't see further optimizations beyond stuff like bits etc. If this is really critical, consider rewriting this portion in C?

提交回复
热议问题