Ver código fonte

bugfix for search: was not checking for nodes to be fully 'used' before returning their flag/count. now we are. tests added to show this. some other small code cleanup (Removed one debug line)

tarfeef101 7 anos atrás
pai
commit
fe562457ae
6 arquivos alterados com 17 adições e 3 exclusões
  1. 1 2
      source1.h
  2. 6 1
      source2.h
  3. 2 0
      test.cc
  4. 8 0
      test2.cc
  5. BIN
      testfile
  6. BIN
      testfile2

+ 1 - 2
source1.h

@@ -310,7 +310,7 @@ class Triehard // compressed binary trie
 				}
 			}
 			
-			return curnode->getFlag();
+			return curnode->getFlag() && !curmag;
 		}
 		
 		void insert(int * val, int len) // assumes valid input
@@ -524,7 +524,6 @@ class Triehard // compressed binary trie
 			
 			int curmag = curnode->getMag();
 			
-			cout << "loop starting" << endl;
 			for (int i = 0; i < len; i++) // each iteration checks the current character for accuracy. it does not prepare for the next character like the preamble
 			{
 				if (val[i]) // if next digit is 1

+ 6 - 1
source2.h

@@ -323,7 +323,12 @@ class Triehard2 // compressed binary trie
 				}
 			}
 			
-			return curnode->getCount();
+			if (!curmag)
+			{
+				return curnode->getCount();
+			}
+			
+			return 0;
 		}
 		
 		void insert(int * val, int len) // assumes valid input

+ 2 - 0
test.cc

@@ -23,9 +23,11 @@ int main()
 	cout << "success! inserted b" << endl;
 	test->myPrintIsBetterThanYoursLogan();
 	cout << "Print Done!" << endl;
+	cout << "Search result for 10110: " << test->search(y, 5) << endl;
 	test->cut(y, 5);
 	cout << "success! cut y" << endl;
 	test->myPrintIsBetterThanYoursLogan();
+	cout << "Search result for 10110: " << test->search(y, 5) << endl;
 	delete test;
 	cout << "success! Completed test" << endl;
 	//while(1);

+ 8 - 0
test2.cc

@@ -27,9 +27,17 @@ int main()
 	cout << "success! inserted b" << endl;
 	test->myPrintIsBetterThanYoursLogan();
 	cout << "Print Done!" << endl;
+	cout << "Search result for 10110: " << test->search(y, 5) << endl;
 	test->cut(y, 5);
 	cout << "success! cut y" << endl;
 	test->myPrintIsBetterThanYoursLogan();
+	cout << "Search result for 10110: " << test->search(y, 5) << endl;
+	test->cut(y, 5);
+	cout << "success! cut y" << endl;
+	test->cut(y, 5);
+	cout << "success! cut y" << endl;
+	test->myPrintIsBetterThanYoursLogan();
+	cout << "Search result for 10110: " << test->search(y, 5) << endl;
 	delete test;
 	cout << "success! Completed test" << endl;
 	//while(1);

BIN
testfile


BIN
testfile2