/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.

    This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. 

    See the LICENSE and COPYING files for more details.
*/

#include "nfold.h"

void appendVector(std::vector<int> &a, std::vector<int> b)
{
	for(std::vector<int>::iterator iter=b.begin();iter!=b.end();++iter)
	{
		a.push_back(*iter);
	}
}
NFold::NFold()
{
}
NFold::~NFold()
{
	for(int i=0;i<(int)folds.size();i++)
		delete folds[i];
}

void NFold::init(int numOfQuestions, int numOfFolds)
{
	for(int i=0;i<numOfFolds;i++)
	{
		folds.push_back(new std::vector<int>);
		for(int j=(numOfQuestions*i)/numOfFolds;j<(numOfQuestions*(i+1))/numOfFolds;j++)
			folds[i]->push_back(j);
	}

	current=0;


}

std::pair<std::vector<int>,std::vector<int> >  NFold::next()
{
	std::vector<int> learning;

	for(int i=0;i<(int)folds.size();i++)
		if(i!=current)
			appendVector(learning,(*folds[i]));


	return std::pair<std::vector<int>,std::vector<int> > (learning,(*folds[current++]));

}
