mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 03:26:01 +00:00
277 lines
40 KiB
HTML
277 lines
40 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>rippled: DecayingSample.h Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr id="projectrow">
|
|
<td id="projectalign">
|
|
<div id="projectname">rippled
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.8 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "search/",'.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(document).ready(function() { init_codefold(0); });
|
|
/* @license-end */
|
|
</script>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<div id="MSearchResults">
|
|
<div class="SRPage">
|
|
<div id="SRIndex">
|
|
<div id="SRResults"></div>
|
|
<div class="SRStatus" id="Loading">Loading...</div>
|
|
<div class="SRStatus" id="Searching">Searching...</div>
|
|
<div class="SRStatus" id="NoMatches">No Matches</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_0103a8ad82dcc2c51f5cde661b4b5cb7.html">xrpl</a></li><li class="navelem"><a class="el" href="dir_f534ca90a4985f34ab325acfbcd39b84.html">basics</a></li> </ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle"><div class="title">DecayingSample.h</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span><span class="comment">//------------------------------------------------------------------------------</span></div>
|
|
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno"> 2</span><span class="comment">/*</span></div>
|
|
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno"> 3</span><span class="comment"> This file is part of rippled: https://github.com/ripple/rippled</span></div>
|
|
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno"> 4</span><span class="comment"> Copyright (c) 2012, 2013 Ripple Labs Inc.</span></div>
|
|
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno"> 5</span><span class="comment"></span> </div>
|
|
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno"> 6</span><span class="comment"> Permission to use, copy, modify, and/or distribute this software for any</span></div>
|
|
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno"> 7</span><span class="comment"> purpose with or without fee is hereby granted, provided that the above</span></div>
|
|
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno"> 8</span><span class="comment"> copyright notice and this permission notice appear in all copies.</span></div>
|
|
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno"> 9</span><span class="comment"></span> </div>
|
|
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span><span class="comment"> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES</span></div>
|
|
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span><span class="comment"> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF</span></div>
|
|
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span><span class="comment"> MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR</span></div>
|
|
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span><span class="comment"> ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES</span></div>
|
|
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span><span class="comment"> WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN</span></div>
|
|
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span><span class="comment"> ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF</span></div>
|
|
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span><span class="comment"> OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.</span></div>
|
|
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span><span class="comment">*/</span></div>
|
|
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"> 18</span><span class="comment">//==============================================================================</span></div>
|
|
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span> </div>
|
|
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span><span class="preprocessor">#ifndef RIPPLE_BASICS_DECAYINGSAMPLE_H_INCLUDED</span></div>
|
|
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span><span class="preprocessor">#define RIPPLE_BASICS_DECAYINGSAMPLE_H_INCLUDED</span></div>
|
|
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> </div>
|
|
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span><span class="preprocessor">#include <<a class="codeRef" href="http://en.cppreference.com/w/cpp/header/chrono.html">chrono</a>></span></div>
|
|
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span><span class="preprocessor">#include <<a class="codeRef" href="http://en.cppreference.com/w/cpp/header/cmath.html">cmath</a>></span></div>
|
|
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> </div>
|
|
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span><span class="keyword">namespace </span><a class="code hl_namespace" href="namespaceripple.html">ripple</a> {</div>
|
|
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> </div>
|
|
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span><span class="keyword">template</span> <<span class="keywordtype">int</span> Window, <span class="keyword">typename</span> Clock></div>
|
|
<div class="foldopen" id="foldopen00032" data-start="{" data-end="};">
|
|
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"><a class="line" href="classripple_1_1DecayingSample.html"> 32</a></span><span class="keyword">class </span><a class="code hl_class" href="classripple_1_1DecayingSample.html">DecayingSample</a></div>
|
|
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span>{</div>
|
|
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span><span class="keyword">public</span>:</div>
|
|
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"><a class="line" href="classripple_1_1DecayingSample.html#a0ae9c6057c3e868399f8cc1d07bca635"> 35</a></span> <span class="keyword">using </span><a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a0ae9c6057c3e868399f8cc1d07bca635">value_type</a> = <span class="keyword">typename</span> Clock::duration::rep;</div>
|
|
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"><a class="line" href="classripple_1_1DecayingSample.html#a901436f0dac882f0d1b53d99bbd77937"> 36</a></span> <span class="keyword">using </span><a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a901436f0dac882f0d1b53d99bbd77937">time_point</a> = <span class="keyword">typename</span> Clock::time_point;</div>
|
|
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> </div>
|
|
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"><a class="line" href="classripple_1_1DecayingSample.html#abe1d19ee0af1f06ec16bbcb9d72d83fc"> 38</a></span> <a class="code hl_function" href="classripple_1_1DecayingSample.html#abe1d19ee0af1f06ec16bbcb9d72d83fc">DecayingSample</a>() = <span class="keyword">delete</span>;</div>
|
|
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> </div>
|
|
<div class="foldopen" id="foldopen00043" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"><a class="line" href="classripple_1_1DecayingSample.html#a2f7df15dc3181f3043527b4aff1cad7d"> 43</a></span> <span class="keyword">explicit</span> <a class="code hl_function" href="classripple_1_1DecayingSample.html#a2f7df15dc3181f3043527b4aff1cad7d">DecayingSample</a>(<a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a901436f0dac882f0d1b53d99bbd77937">time_point</a> now) : <a class="code hl_variable" href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a">m_value</a>(<a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a0ae9c6057c3e868399f8cc1d07bca635">value_type</a>()), <a class="code hl_variable" href="classripple_1_1DecayingSample.html#a6b925abb3876f5e45392bcc96e8511cf">m_when</a>(now)</div>
|
|
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> {</div>
|
|
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> </div>
|
|
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span> <a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a0ae9c6057c3e868399f8cc1d07bca635">value_type</a></div>
|
|
<div class="foldopen" id="foldopen00051" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"><a class="line" href="classripple_1_1DecayingSample.html#a50fc616b35ac6589ed3af61baf9e1dec"> 51</a></span> <a class="code hl_function" href="classripple_1_1DecayingSample.html#a50fc616b35ac6589ed3af61baf9e1dec">add</a>(<a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a0ae9c6057c3e868399f8cc1d07bca635">value_type</a> <a class="code hl_function" href="classripple_1_1DecayingSample.html#aa592c9a4ac598241e496d8962caaf6f0">value</a>, <a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a901436f0dac882f0d1b53d99bbd77937">time_point</a> now)</div>
|
|
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span> {</div>
|
|
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> <a class="code hl_function" href="classripple_1_1DecayingSample.html#a272fa376fd4d4a876d2ff2f6fdca4ec7">decay</a>(now);</div>
|
|
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> <a class="code hl_variable" href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a">m_value</a> += <a class="code hl_function" href="classripple_1_1DecayingSample.html#aa592c9a4ac598241e496d8962caaf6f0">value</a>;</div>
|
|
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> <span class="keywordflow">return</span> <a class="code hl_variable" href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a">m_value</a> / Window;</div>
|
|
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> </div>
|
|
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> <a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a0ae9c6057c3e868399f8cc1d07bca635">value_type</a></div>
|
|
<div class="foldopen" id="foldopen00062" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"><a class="line" href="classripple_1_1DecayingSample.html#aa592c9a4ac598241e496d8962caaf6f0"> 62</a></span> <a class="code hl_function" href="classripple_1_1DecayingSample.html#aa592c9a4ac598241e496d8962caaf6f0">value</a>(<a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a901436f0dac882f0d1b53d99bbd77937">time_point</a> now)</div>
|
|
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> {</div>
|
|
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> <a class="code hl_function" href="classripple_1_1DecayingSample.html#a272fa376fd4d4a876d2ff2f6fdca4ec7">decay</a>(now);</div>
|
|
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> <span class="keywordflow">return</span> <a class="code hl_variable" href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a">m_value</a> / Window;</div>
|
|
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> </div>
|
|
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span><span class="keyword">private</span>:</div>
|
|
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> <span class="comment">// Apply exponential decay based on the specified time.</span></div>
|
|
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> <span class="keywordtype">void</span></div>
|
|
<div class="foldopen" id="foldopen00071" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"><a class="line" href="classripple_1_1DecayingSample.html#a272fa376fd4d4a876d2ff2f6fdca4ec7"> 71</a></span> <a class="code hl_function" href="classripple_1_1DecayingSample.html#a272fa376fd4d4a876d2ff2f6fdca4ec7">decay</a>(<a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a901436f0dac882f0d1b53d99bbd77937">time_point</a> now)</div>
|
|
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> {</div>
|
|
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> <span class="keywordflow">if</span> (now == <a class="code hl_variable" href="classripple_1_1DecayingSample.html#a6b925abb3876f5e45392bcc96e8511cf">m_when</a>)</div>
|
|
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> </div>
|
|
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> <span class="keywordflow">if</span> (<a class="code hl_variable" href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a">m_value</a> != <a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a0ae9c6057c3e868399f8cc1d07bca635">value_type</a>())</div>
|
|
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> {</div>
|
|
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> <a class="code hl_classRef" href="http://en.cppreference.com/w/cpp/types/size_t.html">std::size_t</a> elapsed =</div>
|
|
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> std::chrono::duration_cast<std::chrono::seconds>(now - <a class="code hl_variable" href="classripple_1_1DecayingSample.html#a6b925abb3876f5e45392bcc96e8511cf">m_when</a>)</div>
|
|
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> .count();</div>
|
|
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> </div>
|
|
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> <span class="comment">// A span larger than four times the window decays the</span></div>
|
|
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> <span class="comment">// value to an insignificant amount so just reset it.</span></div>
|
|
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> <span class="comment">//</span></div>
|
|
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> <span class="keywordflow">if</span> (elapsed > 4 * Window)</div>
|
|
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> {</div>
|
|
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> <a class="code hl_variable" href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a">m_value</a> = <a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a0ae9c6057c3e868399f8cc1d07bca635">value_type</a>();</div>
|
|
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> }</div>
|
|
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> <span class="keywordflow">else</span></div>
|
|
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> {</div>
|
|
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> <span class="keywordflow">while</span> (elapsed--)</div>
|
|
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> <a class="code hl_variable" href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a">m_value</a> -= (<a class="code hl_variable" href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a">m_value</a> + Window - 1) / Window;</div>
|
|
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> }</div>
|
|
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> }</div>
|
|
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> </div>
|
|
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> <a class="code hl_variable" href="classripple_1_1DecayingSample.html#a6b925abb3876f5e45392bcc96e8511cf">m_when</a> = now;</div>
|
|
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> </div>
|
|
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> <span class="comment">// Current value in exponential units</span></div>
|
|
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"><a class="line" href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a"> 100</a></span> <a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a0ae9c6057c3e868399f8cc1d07bca635">value_type</a> <a class="code hl_variable" href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a">m_value</a>;</div>
|
|
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> </div>
|
|
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> <span class="comment">// Last time the aging function was applied</span></div>
|
|
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"><a class="line" href="classripple_1_1DecayingSample.html#a6b925abb3876f5e45392bcc96e8511cf"> 103</a></span> <a class="code hl_typedef" href="classripple_1_1DecayingSample.html#a901436f0dac882f0d1b53d99bbd77937">time_point</a> <a class="code hl_variable" href="classripple_1_1DecayingSample.html#a6b925abb3876f5e45392bcc96e8511cf">m_when</a>;</div>
|
|
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span>};</div>
|
|
</div>
|
|
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> </div>
|
|
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span><span class="comment">//------------------------------------------------------------------------------</span></div>
|
|
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> </div>
|
|
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span><span class="keyword">template</span> <<span class="keywordtype">int</span> HalfLife, <span class="keyword">class</span> Clock></div>
|
|
<div class="foldopen" id="foldopen00112" data-start="{" data-end="};">
|
|
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"><a class="line" href="classripple_1_1DecayWindow.html"> 112</a></span><span class="keyword">class </span><a class="code hl_class" href="classripple_1_1DecayWindow.html">DecayWindow</a></div>
|
|
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span>{</div>
|
|
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span><span class="keyword">public</span>:</div>
|
|
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"><a class="line" href="classripple_1_1DecayWindow.html#aa3f16841f2b81e3bbcc19f5496e64fe7"> 115</a></span> <span class="keyword">using </span><a class="code hl_typedef" href="classripple_1_1DecayWindow.html#aa3f16841f2b81e3bbcc19f5496e64fe7">time_point</a> = <span class="keyword">typename</span> Clock::time_point;</div>
|
|
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> </div>
|
|
<div class="foldopen" id="foldopen00117" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"><a class="line" href="classripple_1_1DecayWindow.html#a8771bf6d66c80e687027fd1e0e3dd72a"> 117</a></span> <span class="keyword">explicit</span> <a class="code hl_function" href="classripple_1_1DecayWindow.html#a8771bf6d66c80e687027fd1e0e3dd72a">DecayWindow</a>(<a class="code hl_typedef" href="classripple_1_1DecayWindow.html#aa3f16841f2b81e3bbcc19f5496e64fe7">time_point</a> now) : <a class="code hl_variable" href="classripple_1_1DecayWindow.html#a98e9e4239959749b5bc8f4cf8a3aa124">value_</a>(0), <a class="code hl_variable" href="classripple_1_1DecayWindow.html#a753b4185a2902da00f2f3ebf46efe512">when_</a>(now)</div>
|
|
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> {</div>
|
|
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> </div>
|
|
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span> <span class="keywordtype">void</span></div>
|
|
<div class="foldopen" id="foldopen00122" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"><a class="line" href="classripple_1_1DecayWindow.html#ad3cd95404ae6e74760983eac7cdedd26"> 122</a></span> <a class="code hl_function" href="classripple_1_1DecayWindow.html#ad3cd95404ae6e74760983eac7cdedd26">add</a>(<span class="keywordtype">double</span> <a class="code hl_function" href="classripple_1_1DecayWindow.html#a85439c48487ee30c2aa2bafce7dc795b">value</a>, <a class="code hl_typedef" href="classripple_1_1DecayWindow.html#aa3f16841f2b81e3bbcc19f5496e64fe7">time_point</a> now)</div>
|
|
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno"> 123</span> {</div>
|
|
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno"> 124</span> <a class="code hl_function" href="classripple_1_1DecayWindow.html#a3c1e28310577d634672418a8454e9315">decay</a>(now);</div>
|
|
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno"> 125</span> <a class="code hl_variable" href="classripple_1_1DecayWindow.html#a98e9e4239959749b5bc8f4cf8a3aa124">value_</a> += <a class="code hl_function" href="classripple_1_1DecayWindow.html#a85439c48487ee30c2aa2bafce7dc795b">value</a>;</div>
|
|
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno"> 126</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno"> 127</span> </div>
|
|
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno"> 128</span> <span class="keywordtype">double</span></div>
|
|
<div class="foldopen" id="foldopen00129" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno"><a class="line" href="classripple_1_1DecayWindow.html#a85439c48487ee30c2aa2bafce7dc795b"> 129</a></span> <a class="code hl_function" href="classripple_1_1DecayWindow.html#a85439c48487ee30c2aa2bafce7dc795b">value</a>(<a class="code hl_typedef" href="classripple_1_1DecayWindow.html#aa3f16841f2b81e3bbcc19f5496e64fe7">time_point</a> now)</div>
|
|
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno"> 130</span> {</div>
|
|
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno"> 131</span> <a class="code hl_function" href="classripple_1_1DecayWindow.html#a3c1e28310577d634672418a8454e9315">decay</a>(now);</div>
|
|
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno"> 132</span> <span class="keywordflow">return</span> <a class="code hl_variable" href="classripple_1_1DecayWindow.html#a98e9e4239959749b5bc8f4cf8a3aa124">value_</a> / HalfLife;</div>
|
|
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno"> 133</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno"> 134</span> </div>
|
|
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno"> 135</span><span class="keyword">private</span>:</div>
|
|
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno"> 136</span> <span class="keyword">static_assert</span>(HalfLife > 0, <span class="stringliteral">"half life must be positive"</span>);</div>
|
|
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno"> 137</span> </div>
|
|
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno"> 138</span> <span class="keywordtype">void</span></div>
|
|
<div class="foldopen" id="foldopen00139" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno"><a class="line" href="classripple_1_1DecayWindow.html#a3c1e28310577d634672418a8454e9315"> 139</a></span> <a class="code hl_function" href="classripple_1_1DecayWindow.html#a3c1e28310577d634672418a8454e9315">decay</a>(<a class="code hl_typedef" href="classripple_1_1DecayWindow.html#aa3f16841f2b81e3bbcc19f5496e64fe7">time_point</a> now)</div>
|
|
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno"> 140</span> {</div>
|
|
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno"> 141</span> <span class="keywordflow">if</span> (now <= <a class="code hl_variable" href="classripple_1_1DecayWindow.html#a753b4185a2902da00f2f3ebf46efe512">when_</a>)</div>
|
|
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno"> 142</span> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno"> 143</span> <span class="keyword">using namespace </span><a class="code hl_namespaceRef" href="http://en.cppreference.com/w/namespacestd_1_1chrono.html">std::chrono</a>;</div>
|
|
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno"> 144</span> <span class="keyword">auto</span> <span class="keyword">const</span> elapsed = <a class="code hl_classRef" href="http://en.cppreference.com/w/cpp/chrono/duration.html">duration<double></a>(now - <a class="code hl_variable" href="classripple_1_1DecayWindow.html#a753b4185a2902da00f2f3ebf46efe512">when_</a>).<a class="code hl_functionRef" href="http://en.cppreference.com/w/cpp/chrono/duration/count.html">count</a>();</div>
|
|
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno"> 145</span> <a class="code hl_variable" href="classripple_1_1DecayWindow.html#a98e9e4239959749b5bc8f4cf8a3aa124">value_</a> *= <a class="code hl_functionRef" href="http://en.cppreference.com/w/cpp/numeric/math/pow.html">std::pow</a>(2.0, -elapsed / HalfLife);</div>
|
|
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno"> 146</span> <a class="code hl_variable" href="classripple_1_1DecayWindow.html#a753b4185a2902da00f2f3ebf46efe512">when_</a> = now;</div>
|
|
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno"> 147</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno"> 148</span> </div>
|
|
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno"><a class="line" href="classripple_1_1DecayWindow.html#a98e9e4239959749b5bc8f4cf8a3aa124"> 149</a></span> <span class="keywordtype">double</span> <a class="code hl_variable" href="classripple_1_1DecayWindow.html#a98e9e4239959749b5bc8f4cf8a3aa124">value_</a>;</div>
|
|
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno"><a class="line" href="classripple_1_1DecayWindow.html#a753b4185a2902da00f2f3ebf46efe512"> 150</a></span> <a class="code hl_typedef" href="classripple_1_1DecayWindow.html#aa3f16841f2b81e3bbcc19f5496e64fe7">time_point</a> <a class="code hl_variable" href="classripple_1_1DecayWindow.html#a753b4185a2902da00f2f3ebf46efe512">when_</a>;</div>
|
|
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno"> 151</span>};</div>
|
|
</div>
|
|
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno"> 152</span> </div>
|
|
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno"> 153</span>} <span class="comment">// namespace ripple</span></div>
|
|
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno"> 154</span> </div>
|
|
<div class="line"><a id="l00155" name="l00155"></a><span class="lineno"> 155</span><span class="preprocessor">#endif</span></div>
|
|
<div class="ttc" id="achrono_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/header/chrono.html">chrono</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayWindow_html"><div class="ttname"><a href="classripple_1_1DecayWindow.html">ripple::DecayWindow</a></div><div class="ttdoc">Sampling function using exponential decay to provide a continuous value.</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00112">DecayingSample.h:113</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayWindow_html_a3c1e28310577d634672418a8454e9315"><div class="ttname"><a href="classripple_1_1DecayWindow.html#a3c1e28310577d634672418a8454e9315">ripple::DecayWindow::decay</a></div><div class="ttdeci">void decay(time_point now)</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00139">DecayingSample.h:139</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayWindow_html_a753b4185a2902da00f2f3ebf46efe512"><div class="ttname"><a href="classripple_1_1DecayWindow.html#a753b4185a2902da00f2f3ebf46efe512">ripple::DecayWindow::when_</a></div><div class="ttdeci">time_point when_</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00150">DecayingSample.h:150</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayWindow_html_a85439c48487ee30c2aa2bafce7dc795b"><div class="ttname"><a href="classripple_1_1DecayWindow.html#a85439c48487ee30c2aa2bafce7dc795b">ripple::DecayWindow::value</a></div><div class="ttdeci">double value(time_point now)</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00129">DecayingSample.h:129</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayWindow_html_a8771bf6d66c80e687027fd1e0e3dd72a"><div class="ttname"><a href="classripple_1_1DecayWindow.html#a8771bf6d66c80e687027fd1e0e3dd72a">ripple::DecayWindow::DecayWindow</a></div><div class="ttdeci">DecayWindow(time_point now)</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00117">DecayingSample.h:117</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayWindow_html_a98e9e4239959749b5bc8f4cf8a3aa124"><div class="ttname"><a href="classripple_1_1DecayWindow.html#a98e9e4239959749b5bc8f4cf8a3aa124">ripple::DecayWindow::value_</a></div><div class="ttdeci">double value_</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00149">DecayingSample.h:149</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayWindow_html_aa3f16841f2b81e3bbcc19f5496e64fe7"><div class="ttname"><a href="classripple_1_1DecayWindow.html#aa3f16841f2b81e3bbcc19f5496e64fe7">ripple::DecayWindow::time_point</a></div><div class="ttdeci">typename Clock::time_point time_point</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00115">DecayingSample.h:115</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayWindow_html_ad3cd95404ae6e74760983eac7cdedd26"><div class="ttname"><a href="classripple_1_1DecayWindow.html#ad3cd95404ae6e74760983eac7cdedd26">ripple::DecayWindow::add</a></div><div class="ttdeci">void add(double value, time_point now)</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00122">DecayingSample.h:122</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayingSample_html"><div class="ttname"><a href="classripple_1_1DecayingSample.html">ripple::DecayingSample</a></div><div class="ttdoc">Sampling function using exponential decay to provide a continuous value.</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00032">DecayingSample.h:33</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayingSample_html_a0ae9c6057c3e868399f8cc1d07bca635"><div class="ttname"><a href="classripple_1_1DecayingSample.html#a0ae9c6057c3e868399f8cc1d07bca635">ripple::DecayingSample::value_type</a></div><div class="ttdeci">typename Clock::duration::rep value_type</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00035">DecayingSample.h:35</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayingSample_html_a272fa376fd4d4a876d2ff2f6fdca4ec7"><div class="ttname"><a href="classripple_1_1DecayingSample.html#a272fa376fd4d4a876d2ff2f6fdca4ec7">ripple::DecayingSample::decay</a></div><div class="ttdeci">void decay(time_point now)</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00071">DecayingSample.h:71</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayingSample_html_a2f7df15dc3181f3043527b4aff1cad7d"><div class="ttname"><a href="classripple_1_1DecayingSample.html#a2f7df15dc3181f3043527b4aff1cad7d">ripple::DecayingSample::DecayingSample</a></div><div class="ttdeci">DecayingSample(time_point now)</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00043">DecayingSample.h:43</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayingSample_html_a50fc616b35ac6589ed3af61baf9e1dec"><div class="ttname"><a href="classripple_1_1DecayingSample.html#a50fc616b35ac6589ed3af61baf9e1dec">ripple::DecayingSample::add</a></div><div class="ttdeci">value_type add(value_type value, time_point now)</div><div class="ttdoc">Add a new sample.</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00051">DecayingSample.h:51</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayingSample_html_a6b925abb3876f5e45392bcc96e8511cf"><div class="ttname"><a href="classripple_1_1DecayingSample.html#a6b925abb3876f5e45392bcc96e8511cf">ripple::DecayingSample::m_when</a></div><div class="ttdeci">time_point m_when</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00103">DecayingSample.h:103</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayingSample_html_a901436f0dac882f0d1b53d99bbd77937"><div class="ttname"><a href="classripple_1_1DecayingSample.html#a901436f0dac882f0d1b53d99bbd77937">ripple::DecayingSample::time_point</a></div><div class="ttdeci">typename Clock::time_point time_point</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00036">DecayingSample.h:36</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayingSample_html_aa592c9a4ac598241e496d8962caaf6f0"><div class="ttname"><a href="classripple_1_1DecayingSample.html#aa592c9a4ac598241e496d8962caaf6f0">ripple::DecayingSample::value</a></div><div class="ttdeci">value_type value(time_point now)</div><div class="ttdoc">Retrieve the current value in normalized units.</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00062">DecayingSample.h:62</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayingSample_html_ab9d9cd155bd1388fdb683ba35e1cec2a"><div class="ttname"><a href="classripple_1_1DecayingSample.html#ab9d9cd155bd1388fdb683ba35e1cec2a">ripple::DecayingSample::m_value</a></div><div class="ttdeci">value_type m_value</div><div class="ttdef"><b>Definition</b> <a href="DecayingSample_8h_source.html#l00100">DecayingSample.h:100</a></div></div>
|
|
<div class="ttc" id="aclassripple_1_1DecayingSample_html_abe1d19ee0af1f06ec16bbcb9d72d83fc"><div class="ttname"><a href="classripple_1_1DecayingSample.html#abe1d19ee0af1f06ec16bbcb9d72d83fc">ripple::DecayingSample::DecayingSample</a></div><div class="ttdeci">DecayingSample()=delete</div></div>
|
|
<div class="ttc" id="acmath_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/header/cmath.html">cmath</a></div></div>
|
|
<div class="ttc" id="acount_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/chrono/duration/count.html">std::chrono::duration::count</a></div><div class="ttdeci">T count(T... args)</div></div>
|
|
<div class="ttc" id="aduration_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/chrono/duration.html">std::chrono::duration</a></div></div>
|
|
<div class="ttc" id="anamespaceripple_html"><div class="ttname"><a href="namespaceripple.html">ripple</a></div><div class="ttdoc">Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.</div><div class="ttdef"><b>Definition</b> <a href="algorithm_8h_source.html#l00025">algorithm.h:25</a></div></div>
|
|
<div class="ttc" id="anamespacestd_1_1chrono_html"><div class="ttname"><a href="http://en.cppreference.com/w/namespacestd_1_1chrono.html">std::chrono</a></div></div>
|
|
<div class="ttc" id="apow_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/numeric/math/pow.html">std::pow</a></div><div class="ttdeci">T pow(T... args)</div></div>
|
|
<div class="ttc" id="asize_t_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/types/size_t.html">std::size_t</a></div></div>
|
|
</div><!-- fragment --></div><!-- contents -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8
|
|
</small></address>
|
|
</body>
|
|
</html>
|