⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statisticmanager.cpp

📁 组播密钥的批次更新算法
💻 CPP
字号:
#include "StdAfx.h"
#include "statisticmanager.h"
#include ".\statisticmanager.h"

CStatisticManager::CStatisticManager(void)
: m_respondCounts(0)
, m_averageWaitedTime(0)
, m_totalAverageWaitedTime(0)
, m_totalRespondCounts(0)
{
}

CStatisticManager::~CStatisticManager(void)
{
}

double CStatisticManager::GetAverageWaitedTime(void)
{
	return m_averageWaitedTime;
}

void CStatisticManager::AddInStatistic(unsigned int time)
{
	if (time==0)
		time=GetTickCount();
	this->m_inBuffer.Push(time);
}

int CStatisticManager::GetInAmount(void)
{
	return this->m_inBuffer.GetLength();
}

int CStatisticManager::GetOutAmount(void)
{
	return this->m_outBuffer.GetLength();
}

void CStatisticManager::RemoveInStatistic(void)
{
	if(GetInAmount()>0)
	{
		//取输入队列中的第一个请求时间
		unsigned int requestTime=m_inBuffer.Top();
		unsigned int meetTime=GetTickCount();
		
		m_inBuffer.Pop();

		//平均时间=总时间/响应个数
		double passedTime=m_averageWaitedTime*m_respondCounts;
		double totalPassedTime=m_totalAverageWaitedTime*m_totalRespondCounts;
		m_averageWaitedTime=(passedTime+(double)meetTime-(double)requestTime)/(++m_respondCounts);
		m_totalAverageWaitedTime=(totalPassedTime+(double)meetTime-(double)requestTime)/(++m_totalRespondCounts);
	}
}

void CStatisticManager::AddOutStatistic(int nodeID,unsigned int time)
{
	if (time==0)
		time=GetTickCount();
	this->m_outBuffer.Push(CIDTimePair(nodeID,time));
}

int CStatisticManager::RemoveOutStatistic(void)
{
	if(GetOutAmount()>0)
	{
		//取输出队列中的第一个请求时间
		unsigned int requestTime=m_outBuffer.Top().m_refTime;
		unsigned int meetTime=GetTickCount();
		int nodeID=m_outBuffer.Top().m_nodeID;

		m_outBuffer.Pop();
		
		//平均时间=总时间/响应个数
		double passedTime=m_averageWaitedTime*m_respondCounts;
		double totalPassedTime=m_totalAverageWaitedTime*m_totalRespondCounts;
		m_averageWaitedTime=(passedTime+(double)meetTime-(double)requestTime)/(++m_respondCounts);
		m_totalAverageWaitedTime=(totalPassedTime+(double)meetTime-(double)requestTime)/(++m_totalRespondCounts);
		
		return nodeID;
	}
	return -1;
}

unsigned long CStatisticManager::GetFirstInTime(void)
{
	if(GetInAmount()>0)
		return this->m_inBuffer.Top();
	return 0;
}

unsigned int CStatisticManager::GetFirstOutTime(void)
{
	if(GetOutAmount()>0)
		return this->m_outBuffer.Top().m_refTime;
	return 0;
}

int CStatisticManager::GetRespondCounts(void)
{
	return this->m_respondCounts;
}

void CStatisticManager::ResetTime(void)
{
	this->m_averageWaitedTime=0;
	this->m_respondCounts=0;
}

double CStatisticManager::GetTotalAverageWaitedTime(void)
{
	return m_totalAverageWaitedTime;
}

int CStatisticManager::GetTotalRespondCounts(void)
{
	return m_totalRespondCounts;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -