📄 samples.cc
字号:
/* $Id: samples.cc,v 1.2 2006-08-09 15:20:54 jonathan Exp $ * Jonathan Ledlie, Harvard University. * Copyright 2005. All rights reserved. */#include "sim.h"#include "samples.h"int PING_HISTORY_COUNT = 4;double PING_SAMPLE_PERCENTILE = .25;int MIN_HISTORY_COUNT = 0;Samples::Samples() { ewma = 0; jitterCount = 0; weightedError = 0; vec = new Point (); appVector = new Point ();}Samples::~Samples() { delete vec; delete appVector;}void Samples::addSample (double sample, int myId, int yourId, Point *yourCoord, double yourWeightedError, Point *yourAppCoord, int timestamp) { stamp = timestamp; if (PING_HISTORY_COUNT == -1) { ewma = PING_SAMPLE_PERCENTILE * sample + (1.-PING_SAMPLE_PERCENTILE) + ewma; sample = ewma; } weightedError = yourWeightedError; vec->assign (yourCoord); appVector->assign (yourAppCoord); // toss the sample from the front if (samples.size() > PING_HISTORY_COUNT) samples.pop_front (); // add this guy to the back samples.push_back (sample);}double Samples::getSample () { if (samples.size() > MIN_HISTORY_COUNT) { // sort em deque<double> sortedSamples (samples); sort (sortedSamples.begin(), sortedSamples.end()); int percentile = (int)(samples.size() * PING_SAMPLE_PERCENTILE); double sample_at_percentile = sortedSamples[percentile]; return sample_at_percentile; } else { return -1; }}void Samples::print () { printf ("sample size %d\n", samples.size()); for (int i = 0; i < samples.size(); i++) { printf ("sample %d %f\n", i, samples[i]); }}ostream& operator << (ostream& os, Samples *s) { os << "[sC " << s->vec << " aC " << s->appVector << " wE " << s->weightedError << " s "; for (int i = 0; i < s->samples.size(); i++) { os << s->samples[i] << " "; } os << "]"; return os;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -