[Avida-SVN] r3387 - branches/goings/source/main

goingssh at myxo.css.msu.edu goingssh at myxo.css.msu.edu
Thu Aug 27 20:49:43 PDT 2009


Author: goingssh
Date: 2009-08-27 23:49:43 -0400 (Thu, 27 Aug 2009)
New Revision: 3387

Modified:
   branches/goings/source/main/cGenomeUtil.cc
Log:
Added Charles fix for edit distance so doesn't go off end of array sometimes

Modified: branches/goings/source/main/cGenomeUtil.cc
===================================================================
--- branches/goings/source/main/cGenomeUtil.cc	2009-08-26 16:29:27 UTC (rev 3386)
+++ branches/goings/source/main/cGenomeUtil.cc	2009-08-28 03:49:43 UTC (rev 3387)
@@ -125,14 +125,16 @@
 {
   const int size1 = gen1.GetSize();
   const int size2 = gen2.GetSize();
+ const int min_size = min(size1, size2);
 
-  if (!size1) return size2;
-  if (!size2) return size1;
+  // If either size is zero, return the other one!
+  if (!min_size) return max(size1, size2);
 
   // Count how many direct matches we have at the front and end.
   int match_front = 0, match_end = 0;
-  while (gen1[match_front] == gen2[match_front]) match_front++;
-  while (gen1[size1 - match_end - 1] == gen2[size2 - match_end - 1]) match_end++;
+  while (match_front < min_size && gen1[match_front] == gen2[match_front]) match_front++;
+  while (match_end < min_size &&
+	 gen1[size1 - match_end - 1] == gen2[size2 - match_end - 1]) match_end++;
 
   // We can ignore the last match_end sites since we know they have distance zero.
   const int test_size1 = size1 - match_front - match_end;




More information about the Avida-cvs mailing list