From a8584fcd4e260ca6c395dbbf17466d3f59c3e4c9 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 9 May 2016 15:12:41 -0400
Subject: [PATCH 47/47] FIXME: rename levenshtein_distance to
 calc_edit_distance

---
 gcc/spellcheck-tree.c | 12 +++++------
 gcc/spellcheck.c      | 58 +++++++++++++++++++++++++--------------------------
 gcc/spellcheck.h      | 14 ++++++-------
 3 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/gcc/spellcheck-tree.c b/gcc/spellcheck-tree.c
index 99a8dba..e5adca6 100644
--- a/gcc/spellcheck-tree.c
+++ b/gcc/spellcheck-tree.c
@@ -27,18 +27,18 @@ along with GCC; see the file COPYING3.  If not see
 #include "selftest.h"
 #include "stringpool.h"
 
-/* Calculate Levenshtein distance between two identifiers.  */
+/* Calculate edit distance between two identifiers.  */
 
 edit_distance_t
-levenshtein_distance (tree ident_s, tree ident_t)
+calc_edit_distance (tree ident_s, tree ident_t)
 {
   gcc_assert (TREE_CODE (ident_s) == IDENTIFIER_NODE);
   gcc_assert (TREE_CODE (ident_t) == IDENTIFIER_NODE);
 
-  return levenshtein_distance (IDENTIFIER_POINTER (ident_s),
-			       IDENTIFIER_LENGTH (ident_s),
-			       IDENTIFIER_POINTER (ident_t),
-			       IDENTIFIER_LENGTH (ident_t));
+  return calc_edit_distance (IDENTIFIER_POINTER (ident_s),
+			     IDENTIFIER_LENGTH (ident_s),
+			     IDENTIFIER_POINTER (ident_t),
+			     IDENTIFIER_LENGTH (ident_t));
 }
 
 /* Given TARGET, an identifier, and CANDIDATES, a vec of identifiers,
diff --git a/gcc/spellcheck.c b/gcc/spellcheck.c
index b37b1e4..04cc5f0 100644
--- a/gcc/spellcheck.c
+++ b/gcc/spellcheck.c
@@ -32,8 +32,8 @@ along with GCC; see the file COPYING3.  If not see
    This implementation uses the Wagner-Fischer algorithm.  */
 
 edit_distance_t
-levenshtein_distance (const char *s, int len_s,
-		      const char *t, int len_t)
+calc_edit_distance (const char *s, int len_s,
+		    const char *t, int len_t)
 {
   const bool debug = false;
 
@@ -113,12 +113,12 @@ levenshtein_distance (const char *s, int len_s,
   return result;
 }
 
-/* Calculate Levenshtein distance between two nil-terminated strings.  */
+/* Calculate edit distance between two nil-terminated strings.  */
 
 edit_distance_t
-levenshtein_distance (const char *s, const char *t)
+calc_edit_distance (const char *s, const char *t)
 {
-  return levenshtein_distance (s, strlen (s), t, strlen (t));
+  return calc_edit_distance (s, strlen (s), t, strlen (t));
 }
 
 /* Given TARGET, a non-NULL string, and CANDIDATES, a non-NULL ptr to
@@ -155,29 +155,29 @@ namespace selftest {
 
 /* Selftests.  */
 
-/* Verify that the levenshtein_distance (A, B) equals the expected
+/* Verify that calc_edit_distance (A, B) equals the expected
    value.  */
 
 static void
-levenshtein_distance_unit_test_oneway (const char *a, const char *b,
-				       edit_distance_t expected)
+calc_edit_distance_unit_test_oneway (const char *a, const char *b,
+				     edit_distance_t expected)
 {
-  edit_distance_t actual = levenshtein_distance (a, b);
+  edit_distance_t actual = calc_edit_distance (a, b);
   ASSERT_EQ (actual, expected);
 }
 
 /* Verify that both
-     levenshtein_distance (A, B)
+     calc_edit_distance (A, B)
    and
-     levenshtein_distance (B, A)
+     calc_edit_distance (B, A)
    equal the expected value, to ensure that the function is symmetric.  */
 
 static void
-levenshtein_distance_unit_test (const char *a, const char *b,
-				edit_distance_t expected)
+calc_edit_distance_unit_test (const char *a, const char *b,
+			      edit_distance_t expected)
 {
-  levenshtein_distance_unit_test_oneway (a, b, expected);
-  levenshtein_distance_unit_test_oneway (b, a, expected);
+  calc_edit_distance_unit_test_oneway (a, b, expected);
+  calc_edit_distance_unit_test_oneway (b, a, expected);
 }
 
 /* Verify that find_closest_string is sane.  */
@@ -222,7 +222,7 @@ static const char * const test_data[] = {
   "1234567890123456789012345678901234567890123456789012345678901234567890"
 };
 
-/* Verify that levenshtein_distance appears to be a sane distance function,
+/* Verify that calc_edit_distance appears to be a sane distance function,
    i.e. the conditions for being a metric.  This is done directly for a
    small set of examples, using test_data above.  This is O(N^3) in the size
    of the array, due to the test for the triangle inequality, so we keep the
@@ -238,7 +238,7 @@ test_metric_conditions ()
       for (int j = 0; j < num_test_cases; j++)
 	{
 	  edit_distance_t dist_ij
-	    = levenshtein_distance (test_data[i], test_data[j]);
+	    = calc_edit_distance (test_data[i], test_data[j]);
 
 	  /* Identity of indiscernibles: d(i, j) > 0 iff i == j.  */
 	  if (i == j)
@@ -248,43 +248,43 @@ test_metric_conditions ()
 
 	  /* Symmetry: d(i, j) == d(j, i).  */
 	  edit_distance_t dist_ji
-	    = levenshtein_distance (test_data[j], test_data[i]);
+	    = calc_edit_distance (test_data[j], test_data[i]);
 	  ASSERT_EQ (dist_ij, dist_ji);
 
 	  /* Triangle inequality.  */
 	  for (int k = 0; k < num_test_cases; k++)
 	    {
 	      edit_distance_t dist_ik
-		= levenshtein_distance (test_data[i], test_data[k]);
+		= calc_edit_distance (test_data[i], test_data[k]);
 	      edit_distance_t dist_jk
-		= levenshtein_distance (test_data[j], test_data[k]);
+		= calc_edit_distance (test_data[j], test_data[k]);
 	      ASSERT_TRUE (dist_ik <= dist_ij + dist_jk);
 	    }
 	}
     }
 }
 
-/* Verify levenshtein_distance for a variety of pairs of pre-canned
+/* Verify calc_edit_distance for a variety of pairs of pre-canned
    inputs, comparing against known-good values.  */
 
 void
 spellcheck_c_tests ()
 {
-  levenshtein_distance_unit_test ("", "nonempty", strlen ("nonempty"));
-  levenshtein_distance_unit_test ("saturday", "sunday", 3);
-  levenshtein_distance_unit_test ("foo", "m_foo", 2);
-  levenshtein_distance_unit_test ("hello_world", "HelloWorld", 3);
-  levenshtein_distance_unit_test
+  calc_edit_distance_unit_test ("", "nonempty", strlen ("nonempty"));
+  calc_edit_distance_unit_test ("saturday", "sunday", 3);
+  calc_edit_distance_unit_test ("foo", "m_foo", 2);
+  calc_edit_distance_unit_test ("hello_world", "HelloWorld", 3);
+  calc_edit_distance_unit_test
     ("the quick brown fox jumps over the lazy dog", "dog", 40);
-  levenshtein_distance_unit_test
+  calc_edit_distance_unit_test
     ("the quick brown fox jumps over the lazy dog",
      "the quick brown dog jumps over the lazy fox",
      4);
-  levenshtein_distance_unit_test
+  calc_edit_distance_unit_test
     ("Lorem ipsum dolor sit amet, consectetur adipiscing elit,",
      "All your base are belong to us",
      44);
-  levenshtein_distance_unit_test ("foo", "FOO", 3);
+  calc_edit_distance_unit_test ("foo", "FOO", 3);
 
   test_find_closest_string ();
   test_metric_conditions ();
diff --git a/gcc/spellcheck.h b/gcc/spellcheck.h
index b48cfbc..6922f6d 100644
--- a/gcc/spellcheck.h
+++ b/gcc/spellcheck.h
@@ -25,11 +25,11 @@ const edit_distance_t MAX_EDIT_DISTANCE = UINT_MAX;
 
 /* spellcheck.c  */
 extern edit_distance_t
-levenshtein_distance (const char *s, int len_s,
-		      const char *t, int len_t);
+calc_edit_distance (const char *s, int len_s,
+		    const char *t, int len_t);
 
 extern edit_distance_t
-levenshtein_distance (const char *s, const char *t);
+calc_edit_distance (const char *s, const char *t);
 
 extern const char *
 find_closest_string (const char *target,
@@ -73,7 +73,7 @@ struct edit_distance_traits<const char *>
 
    This type accumulates the best possible match against GOAL_TYPE for
    a sequence of elements of CANDIDATE_TYPE, whilst minimizing the
-   number of calls to levenshtein_distance and to
+   number of calls to calc_edit_distance and to
    edit_distance_traits<T>::get_length.  */
 
 template <typename GOAL_TYPE, typename CANDIDATE_TYPE>
@@ -126,9 +126,9 @@ class best_match
     /* Otherwise, compute the distance and see if the candidate
        has beaten the previous best value.  */
     edit_distance_t dist
-      = levenshtein_distance (m_goal, m_goal_len,
-			      candidate_traits::get_string (candidate),
-			      candidate_len);
+      = calc_edit_distance (m_goal, m_goal_len,
+			    candidate_traits::get_string (candidate),
+			    candidate_len);
     if (dist < m_best_distance)
       {
 	m_best_distance = dist;
-- 
1.8.5.3

