Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Goubet2014-09-24 08:05:51 -0400
committerMikael Barbero2014-10-08 08:19:31 -0400
commiteec3e7d23788a9499d49c5cf8b58ef8f842a63e0 (patch)
treeed420f8a8956a80507ee53f6eb23447a994ca7a4 /plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff
parentd00bcb91d70d1c7c901f196f503c233e6f074695 (diff)
downloadorg.eclipse.emf.compare-eec3e7d23788a9499d49c5cf8b58ef8f842a63e0.tar.gz
org.eclipse.emf.compare-eec3e7d23788a9499d49c5cf8b58ef8f842a63e0.tar.xz
org.eclipse.emf.compare-eec3e7d23788a9499d49c5cf8b58ef8f842a63e0.zip
Optimize dice coefficient storing bigrams within ints
Bigrams are a combination of two char objects, which are stored on 16 bits. We can take advantage of that and store them within ints instead, allowing us to use simple arithemtics instead of String comparison to compare the bigrams together, making the whole dice coefficient computation faster in turn. Change-Id: I532f02cfc1505b5722f3c757c1e933461d1df383
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
index 987d66f83..43ee1d717 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
@@ -524,6 +524,27 @@ public class DiffUtilTest {
}
@Test
+ public void diceCoefficientFullWidth() {
+ final String[] data = new String[] {"ceString", "ceString", "classe", "Classe", "Classe",
+ "UneClasse", "package", "packagedeux", "", "MaClasse", "package", "packageASupprimer",
+ "attribut", "reference", "aa", "aaaa", "aaa", "aaaa", "v1", "v2", "v", "v1", "a", "a", "a",
+ "b", "a", "A", "GGG", "GGGGGG", "night", "nacht", "fullwidth string", "fullwidth string",
+ "fullwidth string", "fullwidth CharSequence" };
+ final double[] similarities = new double[] {1d, 0.8d, 10d / 13d, 12d / 16d, 0d, 12d / 22d, 0d,
+ 2d / 4d, 4d / 5d, 1d / 2d, 1d / 3d, 1d, 0d, 0d, 4d / 7d, 2d / 8d, 1d, 18d / 38d, };
+
+ for (int i = 0; i < data.length; i += 2) {
+ assertEquals("Unexpected result of the dice coefficient for str1 = " + data[i] + " and str2 = "
+ + data[i + 1], similarities[i / 2], DiffUtil.diceCoefficient(data[i], data[i + 1]),
+ Double.MIN_VALUE);
+ // Make sure that the result is symmetric
+ assertEquals("Dice coefficient was not symmetric for str1 = " + data[i] + " and str2 = "
+ + data[i + 1], similarities[i / 2], DiffUtil.diceCoefficient(data[i + 1], data[i]),
+ Double.MIN_VALUE);
+ }
+ }
+
+ @Test
public void diceCoefficientFailure() {
try {
DiffUtil.diceCoefficient(null, null);

Back to the top