bool InMemorySort(int start_index, int num_blocks, vector<string> field_names)
{// InMemorySort for 2-pass algorithm
//count of blocks to sort in main memory
	vector<Tuple> mem_tuples = mem.getTuples(start_index, num_blocks);
	sort(mem_tuples.begin(), mem_tuples.end(), Tuple_Comparison(field_names));
	for(int index=start_index; index< num_blocks; index++)
	{
		mem.getBlock(index)->clear(); // clearing the blocks
	}
	bool success = mem.setTuples(start_index, mem_tuples);
	if(!success)
		cout<<"Error in InMemorySort"<<endl;
	return success;
}
예제 #2
0
//Main Memory Sorting
//In memory sorting operation based on tuples
bool MMSorting(int startMemIndex, int noOfBlocks, vector<string> fieldNames)
{
	//total no of blocks to sort
	vector<Tuple> tuplesInMem = mem.getTuples(startMemIndex, noOfBlocks);
	sort(tuplesInMem.begin(), tuplesInMem.end(), CompareTuple(fieldNames));
	//clear out any data in the given range of memory block
	for(int i=startMemIndex; i< noOfBlocks; i++)
	{
		mem.getBlock(i)->clear();
	}
	bool success = mem.setTuples(startMemIndex, tuplesInMem);
	if(!success)
		cout<<"Error in MMSorting"<<endl;
	return success;
}