From 06afbb98650bbc42d3f52ef8c5f45531b4056b35 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Fri, 23 Jan 2015 16:07:00 +0100
Subject: [PATCH] fix Horspools algorithm enable stringology exact tests

---
 .../stringology/exact/BoyerMooreHorspool.cpp  | 20 +++++--------------
 makefile                                      |  2 ++
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/alib2algo/src/stringology/exact/BoyerMooreHorspool.cpp b/alib2algo/src/stringology/exact/BoyerMooreHorspool.cpp
index a2f6876bf4..eafc56a51f 100644
--- a/alib2algo/src/stringology/exact/BoyerMooreHorspool.cpp
+++ b/alib2algo/src/stringology/exact/BoyerMooreHorspool.cpp
@@ -44,25 +44,15 @@ std::set<unsigned> BoyerMooreHorspool::match(const string::LinearString& string,
 	*/
 
 	size_t haystack_offset = 0;
-	while(haystack_offset + pattern.getContent().size() <= string.getContent().size())
-	{
+	while(haystack_offset + pattern.getContent().size() <= string.getContent().size()) {
 		size_t i = pattern.getContent().size();
-		while(string.getContent().at(haystack_offset + i - 1) == pattern.getContent().at(i - 1))
-		{
+		while(i > 0 && string.getContent().at(haystack_offset + i - 1) == pattern.getContent().at(i - 1)) {
 			i--;
-
-			if(i == 0) // Yay, there is match!!!
-			{
-				occ.insert(haystack_offset);
-				haystack_offset ++;
-				break;
-			}
 		}
 
-		if(i != 0)
-		{
-			haystack_offset += bcs[string.getContent().at(haystack_offset + i - 1)];
-		}
+		// Yay, there is match!!!
+		if(i == 0) occ.insert(haystack_offset);
+		haystack_offset += bcs[string.getContent().at(haystack_offset + pattern.getContent().size() - 1)];
 		//std::cout << haystack_offset << std::endl;
 	}
 	return occ;
diff --git a/makefile b/makefile
index 89afbc69f2..9eb9d672ac 100644
--- a/makefile
+++ b/makefile
@@ -75,6 +75,7 @@ debug  : all-debug
 	./tests.adeterminize.sh debug
 	./tests.aconversion.sh debug
 	./tests.aderivation.aintegral.sh debug
+	./tests.astringology.sh debug
 
 release: all-release
 	mkdir -p $(addsuffix -release, $(BINFOLDER))
@@ -89,6 +90,7 @@ release: all-release
 	./tests.adeterminize.sh release
 	./tests.aconversion.sh release
 	./tests.aderivation.aintegral.sh release
+	./tests.astringology.sh release
 
 clean  : clean-debug   clean-release
 	$(RM) -r bin-debug bin-release
-- 
GitLab