MCPcopy Create free account
hub / github.com/cuberite/cuberite / SetPoints

Method SetPoints

src/ProbabDistrib.cpp:26–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26void cProbabDistrib::SetPoints(const cProbabDistrib::cPoints & a_Points)
27{
28 ASSERT(!a_Points.empty());
29 m_Sum = 0;
30 m_Cumulative.clear();
31 m_Cumulative.reserve(a_Points.size() + 1);
32 int ProbSum = 0;
33 int LastProb = 0;
34 int LastValue = -1;
35 if (a_Points[0].m_Value != 0)
36 {
37 m_Cumulative.push_back(cPoint(0, 0)); // Always push in the [0, 0] point for easier search algorithm bounds
38 LastValue = 0;
39 }
40 for (cPoints::const_iterator itr = a_Points.begin(), end = a_Points.end(); itr != end; ++itr)
41 {
42 if (itr->m_Value == LastValue)
43 {
44 continue;
45 }
46
47 // Add the current trapezoid to the sum:
48 ProbSum += (LastProb + itr->m_Probability) * (itr->m_Value - LastValue) / 2;
49 LastProb = itr->m_Probability;
50 LastValue = itr->m_Value;
51 m_Cumulative.push_back(cPoint(itr->m_Value, ProbSum));
52 } // for itr - a_Points[]
53 if (LastValue != m_MaxValue)
54 {
55 m_Cumulative.push_back(cPoint(m_MaxValue, 0)); // Always push in the last point for easier search algorithm bounds
56 }
57 m_Sum = ProbSum;
58}
59
60
61

Callers

nothing calls this directly

Calls 6

cPointClass · 0.85
emptyMethod · 0.80
clearMethod · 0.80
sizeMethod · 0.80
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected