src/Generic/patterns/CombinationPattern.cpp
/**
 * Virtual method that returns a sequence of PatternReturnVec objects 
 * for a given top-level pattern. It is called only by CombinationPattern,
 * and only in the case of an any-of combination. It produces a cross-product
 * of the pattern returns from the any-of with the pattern returns from the
 * rest of the pattern. If output is nonempty when extendReturns is called,
 * the cross-product will be produced by combining the existing contents with
 * the output from the any-of. The cross-product will be used to fill output,
 * and the previous contents will be deleted. If output is empty when
 * extendReturns is called, output will be filled with a number of 
 * PatternReturnVec objects equal to the number of members of the any-of.
 * Note that a PatternReturnVec object corresponds to the set of args for a
 * single relation.
 * @see http://wiki.d4m.bbn.com/wiki/PatternReturn_Hierarchy for a description of the
 * PatternReturn hierarchy.
 *
 * @param sequence of PatternReturnVec objects for a given pattern
 *
 * @author afrankel@bbn.com
 * @date 2011.03.22
 **/
Virtual method that returns a sequence of PatternReturnVec objects
for a given top-level pattern. It is called only by CombinationPattern,
and only in the case of an any-of combination. It produces a cross-product
of the pattern returns from the any-of with the pattern returns from the
rest of the pattern. If output is nonempty when extendReturns is called,
the cross-product will be produced by combining the existing contents with
the output from the any-of. The cross-product will be used to fill output,
and the previous contents will be deleted. If output is empty when
extendReturns is called, output will be filled with a number of
PatternReturnVec objects equal to the number of members of the any-of.
Note that a PatternReturnVec object corresponds to the set of args for a
single relation.

@param sequence of PatternReturnVec objects for a given pattern


Virtual method that returns a sequence of PatternReturnVec objects for a given top - level pattern . It is called only by CombinationPattern and only in the case of an any - of combination . It produces a cross - product of the pattern returns from the any - of with the pattern returns from the rest of the pattern . If output is nonempty when extendReturns is called the cross - product will be produced by combining the existing contents with the output from the any - of . The cross - product will be used to fill output and the previous contents will be deleted . If output is empty when extendReturns is called output will be filled with a number of PatternReturnVec objects equal to the number of members of the any - of . Note that a PatternReturnVec object corresponds to the set of args for a single relation . @param sequence of PatternReturnVec objects for a given pattern
void CombinationPattern::multiplyReturns(int pattern_count, PatternReturnVecSeq & output) const {
	std::vector< PatternReturnVecSeq > new_seqs(pattern_count);
	std::vector< int > patterns_w_returns;
	for (int i = 0; i < pattern_count; ++i) {
		if (_patternList[i]) {
			_patternList[i]->getReturns(new_seqs[i]); 
		}
		if (!new_seqs[i].empty()) {
			patterns_w_returns.push_back(i);
		}
	}
	size_t n_returns_size = patterns_w_returns.size();
	size_t output_orig_size = output.size();
	if (n_returns_size != 0) {
		if (output_orig_size == 0) {
			BOOST_FOREACH(int pattern_index, patterns_w_returns) {
				BOOST_FOREACH(PatternReturnVec new_vec, new_seqs[pattern_index]) {
					output.push_back(new_vec);
				}
			}
		}
		else {
			PatternReturnVecSeq::iterator iter = output.begin();
			for (size_t i = 0; i < output_orig_size; ++i) {
				BOOST_FOREACH(int pattern_index, patterns_w_returns) {
					BOOST_FOREACH(PatternReturnVec new_vec, new_seqs[pattern_index]) {
						PatternReturnVec v0(*iter);
						BOOST_FOREACH(PatternReturn_ptr new_ptr, new_vec) {
							v0.push_back(new_ptr);
						}
						output.push_back(v0);
					}
				}
				++iter;
			}
			for (size_t i = 0; i < output_orig_size; ++i) {
				output.pop_front();
			}
		}
	}
	return;
}
void CombinationPattern :: multiplyReturns ( int pattern_count , PatternReturnVecSeq & output ) const { std :: vector < PatternReturnVecSeq > new_seqs ( pattern_count ) ; std :: vector < int > patterns_w_returns ; for ( int i = 0 ; i < pattern_count ; ++ i ) { if ( _patternList [ i ] ) { _patternList [ i ] -> getReturns ( new_seqs [ i ] ) ; } if ( ! new_seqs [ i ] . empty ( ) ) { patterns_w_returns . push_back ( i ) ; } } size_t n_returns_size = patterns_w_returns . size ( ) ; size_t output_orig_size = output . size ( ) ; if ( n_returns_size != 0 ) { if ( output_orig_size == 0 ) { BOOST_FOREACH ( int pattern_index , patterns_w_returns ) { BOOST_FOREACH ( PatternReturnVec new_vec , new_seqs [ pattern_index ] ) { output . push_back ( new_vec ) ; } } } else { PatternReturnVecSeq :: iterator iter = output . begin ( ) ; for ( size_t i = 0 ; i < output_orig_size ; ++ i ) { BOOST_FOREACH ( int pattern_index , patterns_w_returns ) { BOOST_FOREACH ( PatternReturnVec new_vec , new_seqs [ pattern_index ] ) { PatternReturnVec v0 ( * iter ) ; BOOST_FOREACH ( PatternReturn_ptr new_ptr , new_vec ) { v0 . push_back ( new_ptr ) ; } output . push_back ( v0 ) ; } } ++ iter ; } for ( size_t i = 0 ; i < output_orig_size ; ++ i ) { output . pop_front ( ) ; } } } return ; }
Virtual method that returns a sequence of PatternReturnVec objects
 for a given top-level pattern.
Virtual method that returns a sequence of PatternReturnVec objects for a given top - level pattern .
// Find the indices of the subpatterns of the top-level pattern that are non-null and have returns,
 // and store them in a vector of ints.
 // These are "new" because they weren't previously contained in output.
 // There were no PatternReturns in *output when we started,
 // so simply push back one PatternReturnVec for each
 // subpattern that has a return.
 // There were already PatternReturnVec objs in output when we started.
 // For each subpattern that has a return, step through each
 // existing PatternReturnVec (in output), create a new PatternReturnVec                  
 // from it, append the newly retrieved PatternReturns to it, and
 // push this PatternReturnVec onto the back of output.
 // For now, we'll keep the old PatternReturnVec objects at the front of output.
 // Now delete the old PatternReturnVec objects. Since the underlying data type 
 // (PatternReturnVecSeq) is a list rather than a vector, this step does not require copying
 // or reallocation.
