src/hotspot/share/utilities/stringUtils.cpp
changeset 49163 580bb0b85f63
parent 47216 71c04702a3d5
child 50335 01e20d8850e3
equal deleted inserted replaced
49162:c200b4700aeb 49163:580bb0b85f63
     1 /*
     1 /*
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    39     ++ replace_count;
    39     ++ replace_count;
    40   }
    40   }
    41 
    41 
    42   return replace_count;
    42   return replace_count;
    43 }
    43 }
       
    44 
       
    45 double StringUtils::similarity(const char* str1, size_t len1, const char* str2, size_t len2) {
       
    46   size_t total = len1 + len2;
       
    47 
       
    48   size_t hit = 0;
       
    49   for (size_t i = 0; i < len1 - 1; i++) {
       
    50     for (size_t j = 0; j < len2 - 1; j++) {
       
    51       if ((str1[i] == str2[j]) && (str1[i+1] == str2[j+1])) {
       
    52         ++hit;
       
    53         break;
       
    54       }
       
    55     }
       
    56   }
       
    57 
       
    58   return 2.0 * (double) hit / (double) total;
       
    59 }