src/hotspot/share/utilities/stringUtils.cpp
changeset 49163 580bb0b85f63
parent 47216 71c04702a3d5
child 50335 01e20d8850e3
--- a/src/hotspot/share/utilities/stringUtils.cpp	Sat Feb 24 22:42:37 2018 -0800
+++ b/src/hotspot/share/utilities/stringUtils.cpp	Mon Feb 26 09:34:20 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,3 +41,19 @@
 
   return replace_count;
 }
+
+double StringUtils::similarity(const char* str1, size_t len1, const char* str2, size_t len2) {
+  size_t total = len1 + len2;
+
+  size_t hit = 0;
+  for (size_t i = 0; i < len1 - 1; i++) {
+    for (size_t j = 0; j < len2 - 1; j++) {
+      if ((str1[i] == str2[j]) && (str1[i+1] == str2[j+1])) {
+        ++hit;
+        break;
+      }
+    }
+  }
+
+  return 2.0 * (double) hit / (double) total;
+}