//+----------------------------------------------------------------------+
//|								    DAPsim								 |
//| Dean Morrison												11/30/06 |
//| University of Florida												 |
//| Department of Electrical and Computer Engineering					 |
//+----------------------------------------------------------------------+
//| Description: DAPsim is a trace-driven simulator developed in C++ for |
//| the purpose of designing, testing, and evaluating demand prepaging 	 |
//| policies.  It currently implements my proposed concept of Dynamically|
//| Adaptive Prepaging, but may be modified to evaluate many other 		 |
//| policies.															 |
//|																		 |
//| Reuse Policy: Use of this software for personal or instructional	 |
//| purposes is granted without fee provided that the source bears a	 |
//| clear and complete citation.										 |
//+----------------------------------------------------------------------+

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <math.h>

#include "main.h"
#ifndef LRU_PAGEQ_H_
#include "LRU_pageQ.h"
#endif //LRU_PAGEQ_H_

using namespace std;

class PrepagedPageQ {
private:
	int consumedAlloc;
	int targetAlloc;
	LRU_pageQ ResidentQ;
	LRU_pageQ NonResidentQ;
	LRU_pageQ DegreeQ;
	int histogram[DEFAULT_MAX_MEM_SIZE];
	int degreeHistogram[DEFAULT_MAX_DEGREE + 2];

public:
	PrepagedPageQ();
	PrepagedPageQ(int newTargetAlloc);

	void setTargetAlloc(int newTargetAlloc);

	int getConsumedAlloc(void);
	int getTargetAlloc(void);

	LRU_pageQ_entry referencePage(unsigned long int pageNumber);

	void addPage(unsigned long int newPage);

	void evictPage(void);

	void printQueueEntries(void);
	void printResidentQueueEntries(void);

	void clearHistogram(void);
	void clearDegreeHistogram(void);
	void incHistogram(int index);
	void decayHistogram(double decayValue);
	void printHistogram(void);
	int getHistogramEntry(int index);

	bool pagePresentInQ(unsigned long int pageNumber);

	void removeResidentPage(unsigned long int pageNumber);
	void removeNonResidentPage(unsigned long int pageNumber);

	void updateDegreeHistogram(unsigned long int pageNumber, int currentDegree);
	void addDegreePage(unsigned long int newPage);
	void incDegreeHistogram(int index);
	int getDegreeHistogramEntry(int index);
	void printDegreeQueue(int currentDegree);
	int getDegreeQueueSize(void);
};