|
|
|
|
@@ -0,0 +1,521 @@
|
|
|
|
|
<!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">
|
|
|
|
|
<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.2"/>
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
|
|
|
<title>Algorithms_in_C++: probability::windowed_median::WindowedMedian Class Reference</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="../../navtree.css" rel="stylesheet" type="text/css"/>
|
|
|
|
|
<script type="text/javascript" src="../../resize.js"></script>
|
|
|
|
|
<script type="text/javascript" src="../../navtreedata.js"></script>
|
|
|
|
|
<script type="text/javascript" src="../../navtree.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>
|
|
|
|
|
<script type="text/x-mathjax-config">
|
|
|
|
|
MathJax.Hub.Config({
|
|
|
|
|
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
|
|
|
|
jax: ["input/TeX","output/HTML-CSS"],
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.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 style="height: 56px;">
|
|
|
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
|
|
|
<div id="projectname">Algorithms_in_C++<span id="projectnumber"> 1.0.0</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="projectbrief">Set of algorithms implemented in C++.</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
<!-- end header part -->
|
|
|
|
|
<!-- Generated by Doxygen 1.9.2 -->
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
|
|
|
var searchBox = new SearchBox("searchBox", "../../search",'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>
|
|
|
|
|
</div><!-- top -->
|
|
|
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
|
|
|
<div id="nav-tree">
|
|
|
|
|
<div id="nav-tree-contents">
|
|
|
|
|
<div id="nav-sync" class="sync"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
|
|
|
class="ui-resizable-handle">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
|
|
|
$(document).ready(function(){initNavTree('df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html','../../'); initResizable(); });
|
|
|
|
|
/* @license-end */
|
|
|
|
|
</script>
|
|
|
|
|
<div id="doc-content">
|
|
|
|
|
<!-- 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">
|
|
|
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
|
|
|
name="MSearchResults" id="MSearchResults">
|
|
|
|
|
</iframe>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="header">
|
|
|
|
|
<div class="summary">
|
|
|
|
|
<a href="#pub-methods">Public Member Functions</a> |
|
|
|
|
|
<a href="#pri-methods">Private Member Functions</a> |
|
|
|
|
|
<a href="#pri-attribs">Private Attributes</a> |
|
|
|
|
|
<a href="../../d1/d47/classprobability_1_1windowed__median_1_1_windowed_median-members.html">List of all members</a> </div>
|
|
|
|
|
<div class="headertitle"><div class="title">probability::windowed_median::WindowedMedian Class Reference</div></div>
|
|
|
|
|
</div><!--header-->
|
|
|
|
|
<div class="contents">
|
|
|
|
|
|
|
|
|
|
<p>A class to calculate the median of a leading sliding window at the back of a stream of integer values.
|
|
|
|
|
<a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#details">More...</a></p>
|
|
|
|
|
<div class="dynheader">
|
|
|
|
|
Collaboration diagram for probability::windowed_median::WindowedMedian:</div>
|
|
|
|
|
<div class="dyncontent">
|
|
|
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d2/d92/classprobability_1_1windowed__median_1_1_windowed_median__coll__graph.svg" width="198" height="142"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
|
|
|
</div>
|
|
|
|
|
<center><span class="legend">[<a target="top" href="../../graph_legend.html">legend</a>]</span></center></div>
|
|
|
|
|
<table class="memberdecls">
|
|
|
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
|
|
|
|
|
Public Member Functions</h2></td></tr>
|
|
|
|
|
<tr class="memitem:aac676369661d15a3eb782c0fee77d45d"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aac676369661d15a3eb782c0fee77d45d">WindowedMedian</a> (size_type windowSize)</td></tr>
|
|
|
|
|
<tr class="memdesc:aac676369661d15a3eb782c0fee77d45d"><td class="mdescLeft"> </td><td class="mdescRight">Constructs a <a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html" title="A class to calculate the median of a leading sliding window at the back of a stream of integer values...">WindowedMedian</a> object. <a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aac676369661d15a3eb782c0fee77d45d">More...</a><br /></td></tr>
|
|
|
|
|
<tr class="separator:aac676369661d15a3eb782c0fee77d45d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
<tr class="memitem:a6b52b7851750f28d53508e63c52a69f7"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a6b52b7851750f28d53508e63c52a69f7">insert</a> (int value)</td></tr>
|
|
|
|
|
<tr class="memdesc:a6b52b7851750f28d53508e63c52a69f7"><td class="mdescLeft"> </td><td class="mdescRight">Insert a new value to the stream. <a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a6b52b7851750f28d53508e63c52a69f7">More...</a><br /></td></tr>
|
|
|
|
|
<tr class="separator:a6b52b7851750f28d53508e63c52a69f7"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
<tr class="memitem:a938cafbdf70dc01e86e9bb12d29ec65d"><td class="memItemLeft" align="right" valign="top">float </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a938cafbdf70dc01e86e9bb12d29ec65d">getMedian</a> () const</td></tr>
|
|
|
|
|
<tr class="memdesc:a938cafbdf70dc01e86e9bb12d29ec65d"><td class="mdescLeft"> </td><td class="mdescRight">Gets the median of the values in the sliding window. <a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a938cafbdf70dc01e86e9bb12d29ec65d">More...</a><br /></td></tr>
|
|
|
|
|
<tr class="separator:a938cafbdf70dc01e86e9bb12d29ec65d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
<tr class="memitem:a61804988fcb1a6caf640f8291979aaa6"><td class="memItemLeft" align="right" valign="top">float </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a61804988fcb1a6caf640f8291979aaa6">getMedianNaive</a> () const</td></tr>
|
|
|
|
|
<tr class="memdesc:a61804988fcb1a6caf640f8291979aaa6"><td class="mdescLeft"> </td><td class="mdescRight">A naive and inefficient method to obtain the median of the sliding window. Used for testing! <a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a61804988fcb1a6caf640f8291979aaa6">More...</a><br /></td></tr>
|
|
|
|
|
<tr class="separator:a61804988fcb1a6caf640f8291979aaa6"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
</table><table class="memberdecls">
|
|
|
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pri-methods" name="pri-methods"></a>
|
|
|
|
|
Private Member Functions</h2></td></tr>
|
|
|
|
|
<tr class="memitem:a3a7f57679e9cd6c9f042dfd0612b2b24"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a3a7f57679e9cd6c9f042dfd0612b2b24">insertToSorted</a> (int value)</td></tr>
|
|
|
|
|
<tr class="memdesc:a3a7f57679e9cd6c9f042dfd0612b2b24"><td class="mdescLeft"> </td><td class="mdescRight">Inserts a value to a sorted multi-value BST. <a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a3a7f57679e9cd6c9f042dfd0612b2b24">More...</a><br /></td></tr>
|
|
|
|
|
<tr class="separator:a3a7f57679e9cd6c9f042dfd0612b2b24"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
<tr class="memitem:af544e271ea19a6fd69a6b3ed6816453e"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#af544e271ea19a6fd69a6b3ed6816453e">eraseFromSorted</a> (int value)</td></tr>
|
|
|
|
|
<tr class="memdesc:af544e271ea19a6fd69a6b3ed6816453e"><td class="mdescLeft"> </td><td class="mdescRight">Erases a value from a sorted multi-value BST. <a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#af544e271ea19a6fd69a6b3ed6816453e">More...</a><br /></td></tr>
|
|
|
|
|
<tr class="separator:af544e271ea19a6fd69a6b3ed6816453e"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
</table><table class="memberdecls">
|
|
|
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pri-attribs" name="pri-attribs"></a>
|
|
|
|
|
Private Attributes</h2></td></tr>
|
|
|
|
|
<tr class="memitem:aafda847b152684578dab891e5268d750"><td class="memItemLeft" align="right" valign="top"><a id="aafda847b152684578dab891e5268d750" name="aafda847b152684578dab891e5268d750"></a>
|
|
|
|
|
const size_type </td><td class="memItemRight" valign="bottom"><b>_windowSize</b></td></tr>
|
|
|
|
|
<tr class="memdesc:aafda847b152684578dab891e5268d750"><td class="mdescLeft"> </td><td class="mdescRight">sliding window size <br /></td></tr>
|
|
|
|
|
<tr class="separator:aafda847b152684578dab891e5268d750"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
<tr class="memitem:a825a7aaef844c9f743a27b268e8569b2"><td class="memItemLeft" align="right" valign="top"><a id="a825a7aaef844c9f743a27b268e8569b2" name="a825a7aaef844c9f743a27b268e8569b2"></a>
|
|
|
|
|
<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/list.html">Window</a> </td><td class="memItemRight" valign="bottom"><b>_window</b></td></tr>
|
|
|
|
|
<tr class="memdesc:a825a7aaef844c9f743a27b268e8569b2"><td class="mdescLeft"> </td><td class="mdescRight">a sliding window of values along the stream <br /></td></tr>
|
|
|
|
|
<tr class="separator:a825a7aaef844c9f743a27b268e8569b2"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
<tr class="memitem:aacd76f078632faee1a8788d031e6c2de"><td class="memItemLeft" align="right" valign="top"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/multiset.html">std::multiset</a>< int > </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aacd76f078632faee1a8788d031e6c2de">_sortedValues</a></td></tr>
|
|
|
|
|
<tr class="separator:aacd76f078632faee1a8788d031e6c2de"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
<tr class="memitem:a55ae3543a76045dffcb5ec7904a32a20"><td class="memItemLeft" align="right" valign="top"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/multiset.html">std::multiset</a>< int >::const_iterator </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a></td></tr>
|
|
|
|
|
<tr class="separator:a55ae3543a76045dffcb5ec7904a32a20"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
|
|
|
<div class="textblock"><p >A class to calculate the median of a leading sliding window at the back of a stream of integer values. </p>
|
|
|
|
|
</div><h2 class="groupheader">Constructor & Destructor Documentation</h2>
|
|
|
|
|
<a id="aac676369661d15a3eb782c0fee77d45d" name="aac676369661d15a3eb782c0fee77d45d"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aac676369661d15a3eb782c0fee77d45d">◆ </a></span>WindowedMedian()</h2>
|
|
|
|
|
|
|
|
|
|
<div class="memitem">
|
|
|
|
|
<div class="memproto">
|
|
|
|
|
<table class="mlabels">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">probability::windowed_median::WindowedMedian::WindowedMedian </td>
|
|
|
|
|
<td>(</td>
|
|
|
|
|
<td class="paramtype">size_type </td>
|
|
|
|
|
<td class="paramname"><em>windowSize</em></td><td>)</td>
|
|
|
|
|
<td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="mlabels-right">
|
|
|
|
|
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">explicit</span></span> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
|
|
|
|
|
<p>Constructs a <a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html" title="A class to calculate the median of a leading sliding window at the back of a stream of integer values...">WindowedMedian</a> object. </p>
|
|
|
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
|
|
|
<table class="params">
|
|
|
|
|
<tr><td class="paramname">windowSize</td><td>Sliding window size </td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
</dd>
|
|
|
|
|
</dl>
|
|
|
|
|
<div class="fragment"><div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span>: <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aafda847b152684578dab891e5268d750">_windowSize</a>(windowSize){};</div>
|
|
|
|
|
<div class="ttc" id="aclassprobability_1_1windowed__median_1_1_windowed_median_html_aafda847b152684578dab891e5268d750"><div class="ttname"><a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aafda847b152684578dab891e5268d750">probability::windowed_median::WindowedMedian::_windowSize</a></div><div class="ttdeci">const size_type _windowSize</div><div class="ttdoc">sliding window size</div><div class="ttdef"><b>Definition:</b> windowed_median.cpp:57</div></div>
|
|
|
|
|
</div><!-- fragment -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<h2 class="groupheader">Member Function Documentation</h2>
|
|
|
|
|
<a id="af544e271ea19a6fd69a6b3ed6816453e" name="af544e271ea19a6fd69a6b3ed6816453e"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#af544e271ea19a6fd69a6b3ed6816453e">◆ </a></span>eraseFromSorted()</h2>
|
|
|
|
|
|
|
|
|
|
<div class="memitem">
|
|
|
|
|
<div class="memproto">
|
|
|
|
|
<table class="mlabels">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">void probability::windowed_median::WindowedMedian::eraseFromSorted </td>
|
|
|
|
|
<td>(</td>
|
|
|
|
|
<td class="paramtype">int </td>
|
|
|
|
|
<td class="paramname"><em>value</em></td><td>)</td>
|
|
|
|
|
<td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="mlabels-right">
|
|
|
|
|
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">private</span></span> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
|
|
|
|
|
<p>Erases a value from a sorted multi-value BST. </p>
|
|
|
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
|
|
|
<table class="params">
|
|
|
|
|
<tr><td class="paramname">value</td><td>Value to insert </td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
</dd>
|
|
|
|
|
</dl>
|
|
|
|
|
<p >If the erased value is on the left branch or the median itself and the number of elements is even, the new median will be the right child of the current one</p>
|
|
|
|
|
<p >O(1) - traversing one step to the right child</p>
|
|
|
|
|
<p >However, if the erased value is on the right branch or the median itself, and the number of elements is odd, the new median will be the left child of the current one</p>
|
|
|
|
|
<p >Find the (first) position of the value we want to erase, and erase it</p>
|
|
|
|
|
<div class="fragment"><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> <span class="keyword">const</span> <span class="keyword">auto</span> sz = <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aacd76f078632faee1a8788d031e6c2de">_sortedValues</a>.size();</div>
|
|
|
|
|
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span><span class="comment"></span> </div>
|
|
|
|
|
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span><span class="comment"> /// If the erased value is on the left branch or the median itself and</span></div>
|
|
|
|
|
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span><span class="comment"> /// the number of elements is even, the new median will be the right</span></div>
|
|
|
|
|
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span><span class="comment"> /// child of the current one</span></div>
|
|
|
|
|
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span><span class="comment"></span> <span class="keywordflow">if</span> (value <= *<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a> && sz % 2 == 0) {</div>
|
|
|
|
|
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> ++<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a>; <span class="comment">/// O(1) - traversing one step to the right child</span></div>
|
|
|
|
|
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> }</div>
|
|
|
|
|
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span><span class="comment"></span> </div>
|
|
|
|
|
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span><span class="comment"> /// However, if the erased value is on the right branch or the median</span></div>
|
|
|
|
|
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span><span class="comment"> /// itself, and the number of elements is odd, the new median will be the</span></div>
|
|
|
|
|
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span><span class="comment"> /// left child of the current one</span></div>
|
|
|
|
|
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span><span class="comment"></span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (value >= *<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a> && sz % 2 != 0) {</div>
|
|
|
|
|
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span> --<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a>; <span class="comment">// O(1) - traversing one step to the left child</span></div>
|
|
|
|
|
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> }</div>
|
|
|
|
|
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span><span class="comment"></span> </div>
|
|
|
|
|
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span><span class="comment"> /// Find the (first) position of the value we want to erase, and erase it</span></div>
|
|
|
|
|
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span><span class="comment"></span> <span class="keyword">const</span> <span class="keyword">auto</span> it = <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aacd76f078632faee1a8788d031e6c2de">_sortedValues</a>.find(value); <span class="comment">// O(logN)</span></div>
|
|
|
|
|
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aacd76f078632faee1a8788d031e6c2de">_sortedValues</a>.erase(it); <span class="comment">// O(logN)</span></div>
|
|
|
|
|
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> }</div>
|
|
|
|
|
<div class="ttc" id="aclassprobability_1_1windowed__median_1_1_windowed_median_html_a55ae3543a76045dffcb5ec7904a32a20"><div class="ttname"><a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">probability::windowed_median::WindowedMedian::_itMedian</a></div><div class="ttdeci">std::multiset< int >::const_iterator _itMedian</div><div class="ttdef"><b>Definition:</b> windowed_median.cpp:62</div></div>
|
|
|
|
|
<div class="ttc" id="aclassprobability_1_1windowed__median_1_1_windowed_median_html_aacd76f078632faee1a8788d031e6c2de"><div class="ttname"><a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aacd76f078632faee1a8788d031e6c2de">probability::windowed_median::WindowedMedian::_sortedValues</a></div><div class="ttdeci">std::multiset< int > _sortedValues</div><div class="ttdef"><b>Definition:</b> windowed_median.cpp:59</div></div>
|
|
|
|
|
</div><!-- fragment -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<a id="a938cafbdf70dc01e86e9bb12d29ec65d" name="a938cafbdf70dc01e86e9bb12d29ec65d"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a938cafbdf70dc01e86e9bb12d29ec65d">◆ </a></span>getMedian()</h2>
|
|
|
|
|
|
|
|
|
|
<div class="memitem">
|
|
|
|
|
<div class="memproto">
|
|
|
|
|
<table class="mlabels">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">float probability::windowed_median::WindowedMedian::getMedian </td>
|
|
|
|
|
<td>(</td>
|
|
|
|
|
<td class="paramname"></td><td>)</td>
|
|
|
|
|
<td> const</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="mlabels-right">
|
|
|
|
|
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
|
|
|
|
|
<p>Gets the median of the values in the sliding window. </p>
|
|
|
|
|
<dl class="section return"><dt>Returns</dt><dd>Median of sliding window. For even window size return the average between the two values in the middle </dd></dl>
|
|
|
|
|
<p >O(1)</p>
|
|
|
|
|
<div class="fragment"><div class="line"><a id="l00147" name="l00147"></a><span class="lineno"> 147</span> {</div>
|
|
|
|
|
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno"> 148</span> <span class="keywordflow">if</span> (<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aacd76f078632faee1a8788d031e6c2de">_sortedValues</a>.size() % 2 != 0) {</div>
|
|
|
|
|
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno"> 149</span> <span class="keywordflow">return</span> *<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a>; <span class="comment">// O(1)</span></div>
|
|
|
|
|
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno"> 150</span> }</div>
|
|
|
|
|
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno"> 151</span> <span class="keywordflow">return</span> 0.5f * *<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a> + 0.5f * *<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/iterator/next.html">next</a>(<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a>); <span class="comment">/// O(1)</span></div>
|
|
|
|
|
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno"> 152</span> }</div>
|
|
|
|
|
<div class="ttc" id="anext_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/iterator/next.html">std::next</a></div><div class="ttdeci">T next(T... args)</div></div>
|
|
|
|
|
</div><!-- fragment -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<a id="a61804988fcb1a6caf640f8291979aaa6" name="a61804988fcb1a6caf640f8291979aaa6"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a61804988fcb1a6caf640f8291979aaa6">◆ </a></span>getMedianNaive()</h2>
|
|
|
|
|
|
|
|
|
|
<div class="memitem">
|
|
|
|
|
<div class="memproto">
|
|
|
|
|
<table class="mlabels">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">float probability::windowed_median::WindowedMedian::getMedianNaive </td>
|
|
|
|
|
<td>(</td>
|
|
|
|
|
<td class="paramname"></td><td>)</td>
|
|
|
|
|
<td> const</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="mlabels-right">
|
|
|
|
|
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
|
|
|
|
|
<p>A naive and inefficient method to obtain the median of the sliding window. Used for testing! </p>
|
|
|
|
|
<dl class="section return"><dt>Returns</dt><dd>Median of sliding window. For even window size return the average between the two values in the middle </dd></dl>
|
|
|
|
|
<p >Sort window - O(NlogN)</p>
|
|
|
|
|
<p >Find value in the middle - O(N)</p>
|
|
|
|
|
<p >O(N)</p>
|
|
|
|
|
<div class="fragment"><div class="line"><a id="l00160" name="l00160"></a><span class="lineno"> 160</span> {</div>
|
|
|
|
|
<div class="line"><a id="l00161" name="l00161"></a><span class="lineno"> 161</span> <span class="keyword">auto</span> window = <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a825a7aaef844c9f743a27b268e8569b2">_window</a>;</div>
|
|
|
|
|
<div class="line"><a id="l00162" name="l00162"></a><span class="lineno"> 162</span> window.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/list/sort.html">sort</a>(); <span class="comment">/// Sort window - O(NlogN)</span></div>
|
|
|
|
|
<div class="line"><a id="l00163" name="l00163"></a><span class="lineno"> 163</span> <span class="keyword">auto</span> median =</div>
|
|
|
|
|
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno"> 164</span> *<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/iterator/next.html">next</a>(window.begin(),</div>
|
|
|
|
|
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno"> 165</span> window.size() / 2); <span class="comment">/// Find value in the middle - O(N)</span></div>
|
|
|
|
|
<div class="line"><a id="l00166" name="l00166"></a><span class="lineno"> 166</span> <span class="keywordflow">if</span> (window.size() % 2 != 0) {</div>
|
|
|
|
|
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno"> 167</span> <span class="keywordflow">return</span> median;</div>
|
|
|
|
|
<div class="line"><a id="l00168" name="l00168"></a><span class="lineno"> 168</span> }</div>
|
|
|
|
|
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno"> 169</span> <span class="keywordflow">return</span> 0.5f * median +</div>
|
|
|
|
|
<div class="line"><a id="l00170" name="l00170"></a><span class="lineno"> 170</span> 0.5f * *<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/iterator/next.html">next</a>(window.begin(), window.size() / 2 - 1); <span class="comment">/// O(N)</span></div>
|
|
|
|
|
<div class="line"><a id="l00171" name="l00171"></a><span class="lineno"> 171</span> }</div>
|
|
|
|
|
<div class="ttc" id="aclassprobability_1_1windowed__median_1_1_windowed_median_html_a825a7aaef844c9f743a27b268e8569b2"><div class="ttname"><a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a825a7aaef844c9f743a27b268e8569b2">probability::windowed_median::WindowedMedian::_window</a></div><div class="ttdeci">Window _window</div><div class="ttdoc">a sliding window of values along the stream</div><div class="ttdef"><b>Definition:</b> windowed_median.cpp:58</div></div>
|
|
|
|
|
<div class="ttc" id="asort_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/list/sort.html">std::list::sort</a></div><div class="ttdeci">T sort(T... args)</div></div>
|
|
|
|
|
</div><!-- fragment --><div class="dynheader">
|
|
|
|
|
Here is the call graph for this function:</div>
|
|
|
|
|
<div class="dyncontent">
|
|
|
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median_a61804988fcb1a6caf640f8291979aaa6_cgraph.svg" width="339" height="67"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<a id="a6b52b7851750f28d53508e63c52a69f7" name="a6b52b7851750f28d53508e63c52a69f7"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a6b52b7851750f28d53508e63c52a69f7">◆ </a></span>insert()</h2>
|
|
|
|
|
|
|
|
|
|
<div class="memitem">
|
|
|
|
|
<div class="memproto">
|
|
|
|
|
<table class="mlabels">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">void probability::windowed_median::WindowedMedian::insert </td>
|
|
|
|
|
<td>(</td>
|
|
|
|
|
<td class="paramtype">int </td>
|
|
|
|
|
<td class="paramname"><em>value</em></td><td>)</td>
|
|
|
|
|
<td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="mlabels-right">
|
|
|
|
|
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
|
|
|
|
|
<p>Insert a new value to the stream. </p>
|
|
|
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
|
|
|
<table class="params">
|
|
|
|
|
<tr><td class="paramname">value</td><td>New value to insert </td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
</dd>
|
|
|
|
|
</dl>
|
|
|
|
|
<p >Push new value to the back of the sliding window - O(1)</p>
|
|
|
|
|
<p >If exceeding size of window, pop from its left side</p>
|
|
|
|
|
<p >Erase from the multi-value BST the window left side value</p>
|
|
|
|
|
<p >Pop the left side value from the window - O(1)</p>
|
|
|
|
|
<div class="fragment"><div class="line"><a id="l00128" name="l00128"></a><span class="lineno"> 128</span> {</div>
|
|
|
|
|
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno"> 129</span> <span class="comment"></span></div>
|
|
|
|
|
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno"> 130</span><span class="comment"> /// Push new value to the back of the sliding window - O(1)</span></div>
|
|
|
|
|
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno"> 131</span><span class="comment"></span> <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a825a7aaef844c9f743a27b268e8569b2">_window</a>.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/list/push_back.html">push_back</a>(value);</div>
|
|
|
|
|
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno"> 132</span> <a class="code hl_function" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a3a7f57679e9cd6c9f042dfd0612b2b24">insertToSorted</a>(value); <span class="comment">// Insert value to the multi-value BST - O(logN)</span></div>
|
|
|
|
|
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno"> 133</span> <span class="keywordflow">if</span> (<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a825a7aaef844c9f743a27b268e8569b2">_window</a>.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/list/size.html">size</a>() > <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aafda847b152684578dab891e5268d750">_windowSize</a>) { <span class="comment">/// If exceeding size of window, pop</span><span class="comment"></span></div>
|
|
|
|
|
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno"> 134</span><span class="comment"> /// from its left side</span></div>
|
|
|
|
|
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno"> 135</span><span class="comment"></span> <a class="code hl_function" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#af544e271ea19a6fd69a6b3ed6816453e">eraseFromSorted</a>(<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a825a7aaef844c9f743a27b268e8569b2">_window</a>.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/list/front.html">front</a>()); <span class="comment">/// Erase from the multi-value BST</span><span class="comment"></span></div>
|
|
|
|
|
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno"> 136</span><span class="comment"> /// the window left side value</span></div>
|
|
|
|
|
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno"> 137</span><span class="comment"></span> <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a825a7aaef844c9f743a27b268e8569b2">_window</a></div>
|
|
|
|
|
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno"> 138</span> .<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/list/pop_front.html">pop_front</a>(); <span class="comment">/// Pop the left side value from the window - O(1)</span></div>
|
|
|
|
|
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno"> 139</span> }</div>
|
|
|
|
|
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno"> 140</span> }</div>
|
|
|
|
|
<div class="ttc" id="aclassprobability_1_1windowed__median_1_1_windowed_median_html_a3a7f57679e9cd6c9f042dfd0612b2b24"><div class="ttname"><a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a3a7f57679e9cd6c9f042dfd0612b2b24">probability::windowed_median::WindowedMedian::insertToSorted</a></div><div class="ttdeci">void insertToSorted(int value)</div><div class="ttdoc">Inserts a value to a sorted multi-value BST.</div><div class="ttdef"><b>Definition:</b> windowed_median.cpp:69</div></div>
|
|
|
|
|
<div class="ttc" id="aclassprobability_1_1windowed__median_1_1_windowed_median_html_af544e271ea19a6fd69a6b3ed6816453e"><div class="ttname"><a href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#af544e271ea19a6fd69a6b3ed6816453e">probability::windowed_median::WindowedMedian::eraseFromSorted</a></div><div class="ttdeci">void eraseFromSorted(int value)</div><div class="ttdoc">Erases a value from a sorted multi-value BST.</div><div class="ttdef"><b>Definition:</b> windowed_median.cpp:95</div></div>
|
|
|
|
|
<div class="ttc" id="afront_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/list/front.html">std::list::front</a></div><div class="ttdeci">T front(T... args)</div></div>
|
|
|
|
|
<div class="ttc" id="apop_front_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/list/pop_front.html">std::list::pop_front</a></div><div class="ttdeci">T pop_front(T... args)</div></div>
|
|
|
|
|
<div class="ttc" id="apush_back_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/list/push_back.html">std::list::push_back</a></div><div class="ttdeci">T push_back(T... args)</div></div>
|
|
|
|
|
<div class="ttc" id="asize_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/list/size.html">std::list::size</a></div><div class="ttdeci">T size(T... args)</div></div>
|
|
|
|
|
</div><!-- fragment --><div class="dynheader">
|
|
|
|
|
Here is the call graph for this function:</div>
|
|
|
|
|
<div class="dyncontent">
|
|
|
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median_a6b52b7851750f28d53508e63c52a69f7_cgraph.svg" width="432" height="350"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<a id="a3a7f57679e9cd6c9f042dfd0612b2b24" name="a3a7f57679e9cd6c9f042dfd0612b2b24"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a3a7f57679e9cd6c9f042dfd0612b2b24">◆ </a></span>insertToSorted()</h2>
|
|
|
|
|
|
|
|
|
|
<div class="memitem">
|
|
|
|
|
<div class="memproto">
|
|
|
|
|
<table class="mlabels">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">void probability::windowed_median::WindowedMedian::insertToSorted </td>
|
|
|
|
|
<td>(</td>
|
|
|
|
|
<td class="paramtype">int </td>
|
|
|
|
|
<td class="paramname"><em>value</em></td><td>)</td>
|
|
|
|
|
<td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="mlabels-right">
|
|
|
|
|
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">private</span></span> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
|
|
|
|
|
<p>Inserts a value to a sorted multi-value BST. </p>
|
|
|
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
|
|
|
<table class="params">
|
|
|
|
|
<tr><td class="paramname">value</td><td>Value to insert </td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
</dd>
|
|
|
|
|
</dl>
|
|
|
|
|
<p >Insert value to BST - O(logN)</p>
|
|
|
|
|
<p >For the first value, set median iterator to BST root</p>
|
|
|
|
|
<p >If new value goes to left tree branch, and number of elements is even, the new median in the balanced tree is the left child of the median before the insertion</p>
|
|
|
|
|
<p >However, if the new value goes to the right branch, the previous median's right child is the new median in the balanced tree</p>
|
|
|
|
|
<p >O(1) - traversing one step to the right child</p>
|
|
|
|
|
<div class="fragment"><div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> {</div>
|
|
|
|
|
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aacd76f078632faee1a8788d031e6c2de">_sortedValues</a>.insert(value); <span class="comment">/// Insert value to BST - O(logN)</span></div>
|
|
|
|
|
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> <span class="keyword">const</span> <span class="keyword">auto</span> sz = <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aacd76f078632faee1a8788d031e6c2de">_sortedValues</a>.size();</div>
|
|
|
|
|
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> <span class="keywordflow">if</span> (sz == 1) { <span class="comment">/// For the first value, set median iterator to BST root</span></div>
|
|
|
|
|
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a> = <a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#aacd76f078632faee1a8788d031e6c2de">_sortedValues</a>.begin();</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="comment"></span> </div>
|
|
|
|
|
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span><span class="comment"> /// If new value goes to left tree branch, and number of elements is</span></div>
|
|
|
|
|
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span><span class="comment"> /// even, the new median in the balanced tree is the left child of the</span></div>
|
|
|
|
|
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span><span class="comment"> /// median before the insertion</span></div>
|
|
|
|
|
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span><span class="comment"></span> <span class="keywordflow">if</span> (value < *<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a> && sz % 2 == 0) {</div>
|
|
|
|
|
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> --<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a>; <span class="comment">// O(1) - traversing one step to the left child</span></div>
|
|
|
|
|
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> }</div>
|
|
|
|
|
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span><span class="comment"></span> </div>
|
|
|
|
|
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span><span class="comment"> /// However, if the new value goes to the right branch, the previous</span></div>
|
|
|
|
|
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span><span class="comment"> /// median's right child is the new median in the balanced tree</span></div>
|
|
|
|
|
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span><span class="comment"></span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (value >= *<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a> && sz % 2 != 0) {</div>
|
|
|
|
|
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> ++<a class="code hl_variable" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html#a55ae3543a76045dffcb5ec7904a32a20">_itMedian</a>; <span class="comment">/// O(1) - traversing one step to the right child</span></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> }</div>
|
|
|
|
|
</div><!-- fragment -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<h2 class="groupheader">Member Data Documentation</h2>
|
|
|
|
|
<a id="a55ae3543a76045dffcb5ec7904a32a20" name="a55ae3543a76045dffcb5ec7904a32a20"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a55ae3543a76045dffcb5ec7904a32a20">◆ </a></span>_itMedian</h2>
|
|
|
|
|
|
|
|
|
|
<div class="memitem">
|
|
|
|
|
<div class="memproto">
|
|
|
|
|
<table class="mlabels">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/multiset.html">std::multiset</a><int>::const_iterator probability::windowed_median::WindowedMedian::_itMedian</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="mlabels-right">
|
|
|
|
|
<span class="mlabels"><span class="mlabel">private</span></span> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
<p >an iterator that points to the root of the multi-value BST </p>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<a id="aacd76f078632faee1a8788d031e6c2de" name="aacd76f078632faee1a8788d031e6c2de"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aacd76f078632faee1a8788d031e6c2de">◆ </a></span>_sortedValues</h2>
|
|
|
|
|
|
|
|
|
|
<div class="memitem">
|
|
|
|
|
<div class="memproto">
|
|
|
|
|
<table class="mlabels">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/multiset.html">std::multiset</a><int> probability::windowed_median::WindowedMedian::_sortedValues</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="mlabels-right">
|
|
|
|
|
<span class="mlabels"><span class="mlabel">private</span></span> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
<p >a DS to represent a balanced multi-value binary search tree (BST) </p>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<hr/>The documentation for this class was generated from the following file:<ul>
|
|
|
|
|
<li>probability/<a class="el" href="../../d1/ded/windowed__median_8cpp.html">windowed_median.cpp</a></li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div><!-- contents -->
|
|
|
|
|
</div><!-- doc-content -->
|
|
|
|
|
<!-- start footer part -->
|
|
|
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
|
|
|
<ul>
|
|
|
|
|
<li class="navelem"><a class="el" href="../../d4/ded/namespaceprobability.html">probability</a></li><li class="navelem"><b>windowed_median</b></li><li class="navelem"><a class="el" href="../../df/d34/classprobability_1_1windowed__median_1_1_windowed_median.html">WindowedMedian</a></li>
|
|
|
|
|
<li class="footer">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.2 </li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|