From 011c0c9e9b5785699eefce08b3d03383ae622863 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Thu, 9 Feb 2017 13:06:30 +0100
Subject: [PATCH] simplification of position heap query algorithm

---
 .../stringology/query/PositionHeapFactors.h   | 20 +++++++------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/alib2algo/src/stringology/query/PositionHeapFactors.h b/alib2algo/src/stringology/query/PositionHeapFactors.h
index 665d6d3a42..0f0eeb2d54 100644
--- a/alib2algo/src/stringology/query/PositionHeapFactors.h
+++ b/alib2algo/src/stringology/query/PositionHeapFactors.h
@@ -70,29 +70,23 @@ std::set < unsigned > PositionHeapFactors::query ( const indexes::PositionHeap <
 	unsigned depth = 0;
 	unsigned indexedStringSize = positionHeap.getString ( ).size ( );
 
-	if(common::GlobalData::verbose)
-		std::clog << "on path possible occ (raw, string index): (" << node->getData ( ) << ", " << indexedStringSize - node->getData ( ) << ")";
+	for ( const SymbolType & symbol : string.getContent ( ) ) {
 
-	if ( checkOcc ( string, depth, positionHeap.getString ( ), indexedStringSize - node->getData ( ) ) )
-		res.insert ( indexedStringSize - node->getData ( ) );
+		if(common::GlobalData::verbose)
+			std::clog << "on path possible occ (raw, string index): (" << node->getData ( ) << ", " << indexedStringSize - node->getData ( ) << ")";
+
+		if ( checkOcc ( string, depth, positionHeap.getString ( ), indexedStringSize - node->getData ( ) ) )
+			res.insert ( indexedStringSize - node->getData ( ) );
 
-	for ( const SymbolType & symbol : string.getContent ( ) ) {
 		auto iter = node->getChildren ( ).find ( symbol );
 		if ( iter == node->getChildren ( ).end ( ) )
 			return res;
 
 		depth++;
 		node = & iter->second;
-
-		if(common::GlobalData::verbose)
-			std::clog << "on path possible occ (raw, string index): (" << node->getData ( ) << ", " << indexedStringSize - node->getData ( ) << ")";
-
-		if ( checkOcc ( string, depth, positionHeap.getString ( ), indexedStringSize - node->getData ( ) ) )
-			res.insert ( indexedStringSize - node->getData ( ) );
 	}
 
-	for ( const std::pair < SymbolType, std::trie < SymbolType, unsigned > > & child : node->getChildren ( ) )
-		accumulateResult ( child.second, res, indexedStringSize );
+	accumulateResult ( * node, res, indexedStringSize );
 	return res;
 }
 
-- 
GitLab