Files
C-Plus-Plus/d3/db3/lru__cache_8cpp.html
2023-01-22 19:44:10 +00:00

497 lines
34 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.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: others/lru_cache.cpp File 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 id="projectrow">
<td id="projectalign">
<div id="projectname">Algorithms_in_C++<span id="projectnumber">&#160;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.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;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&amp;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&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('d3/db3/lru__cache_8cpp.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">
<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 class="header">
<div class="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="#namespaces">Namespaces</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle"><div class="title">lru_cache.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
<p>An implementation of <a href="https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)" target="_blank">LRU Cache</a>. Lru is a part of cache algorithms (also frequently called cache replacement algorithms or cache replacement policies).
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;cassert&gt;</code><br />
<code>#include &lt;iostream&gt;</code><br />
<code>#include &lt;list&gt;</code><br />
<code>#include &lt;unordered_map&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for lru_cache.cpp:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d1/d6d/lru__cache_8cpp__incl.svg" width="371" height="110"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html">others::lru_cache::LRUCache</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">LRU cache class. <a href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="namespaces" name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:d0/d6f/namespaceothers"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d6f/namespaceothers.html">others</a></td></tr>
<tr class="memdesc:d0/d6f/namespaceothers"><td class="mdescLeft">&#160;</td><td class="mdescRight">for <code>vector</code> <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:d8/dcd/namespacelru__cache"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d8/dcd/namespacelru__cache.html">lru_cache</a></td></tr>
<tr class="memdesc:d8/dcd/namespacelru__cache"><td class="mdescLeft">&#160;</td><td class="mdescRight">Implementation of the <a href="https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)" target="_blank">LRU caching algorithm</a> <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a24d21a345ed06f7fba6919718cf3e058"><td class="memTemplParams" colspan="2">template&lt;typename T &gt; </td></tr>
<tr class="memitem:a24d21a345ed06f7fba6919718cf3e058"><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="../../d3/db3/lru__cache_8cpp.html#a24d21a345ed06f7fba6919718cf3e058">lru_tests::log</a> (T msg)</td></tr>
<tr class="memdesc:a24d21a345ed06f7fba6919718cf3e058"><td class="mdescLeft">&#160;</td><td class="mdescRight">A function to print given message on console. <br /></td></tr>
<tr class="separator:a24d21a345ed06f7fba6919718cf3e058"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6401e8f2d41d8cc9cd0e52ab381608d4"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/db3/lru__cache_8cpp.html#a6401e8f2d41d8cc9cd0e52ab381608d4">lru_tests::test_1</a> ()</td></tr>
<tr class="memdesc:a6401e8f2d41d8cc9cd0e52ab381608d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">A simple test case The assert statement will check expected hist and miss to resultant hits and miss. <br /></td></tr>
<tr class="separator:a6401e8f2d41d8cc9cd0e52ab381608d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4b02e288a407876a8d6024f98a2a25ec"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/db3/lru__cache_8cpp.html#a4b02e288a407876a8d6024f98a2a25ec">lru_tests::test_2</a> ()</td></tr>
<tr class="memdesc:a4b02e288a407876a8d6024f98a2a25ec"><td class="mdescLeft">&#160;</td><td class="mdescRight">A test case contains hits more than cache size The assert statement will check expected hist and miss to resultant hits and miss. <br /></td></tr>
<tr class="separator:a4b02e288a407876a8d6024f98a2a25ec"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a01ec21fc91ddafd964ae2035ba7892c0"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/db3/lru__cache_8cpp.html#a01ec21fc91ddafd964ae2035ba7892c0">lru_tests::test_3</a> ()</td></tr>
<tr class="memdesc:a01ec21fc91ddafd964ae2035ba7892c0"><td class="mdescLeft">&#160;</td><td class="mdescRight">A simple test case The assert statement will check expected hist and miss to resultant hits and miss. <br /></td></tr>
<tr class="separator:a01ec21fc91ddafd964ae2035ba7892c0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6a3be6d8871b1f5dc03688da8f3ee9e6"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/db3/lru__cache_8cpp.html#a6a3be6d8871b1f5dc03688da8f3ee9e6">lru_tests::run_tests</a> ()</td></tr>
<tr class="memdesc:a6a3be6d8871b1f5dc03688da8f3ee9e6"><td class="mdescLeft">&#160;</td><td class="mdescRight">A function to invoke all test cases. <br /></td></tr>
<tr class="separator:a6a3be6d8871b1f5dc03688da8f3ee9e6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/db3/lru__cache_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <br /></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>An implementation of <a href="https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)" target="_blank">LRU Cache</a>. Lru is a part of cache algorithms (also frequently called cache replacement algorithms or cache replacement policies). </p>
<h3><a class="anchor" id="autotoc_md95"></a>
Logic</h3>
<ul>
<li>Discards the least recently used items first.</li>
<li>This algorithm requires keeping track of what was used when, which is expensive if one wants to make sure the algorithm always discards the least recently used item.</li>
<li>General implementations of this technique require keeping "age bits" for cache-lines and track the "Least Recently Used" cache-line based on age-bits.</li>
<li>In such an implementation, every time a cache-line is used, the age of all other cache-lines changes</li>
</ul>
<h3><a class="anchor" id="autotoc_md96"></a>
Algorithm explanation</h3>
<p>For a cache of page frame x:</p><ul>
<li>Check if the page is present in cache.</li>
<li>If not present, then check is the cache is full or not:</li>
<li>If the cache is full, REMOVE the last element from the cache.</li>
<li>If the element is present in cache, then shift that element to first position in cache from its original position.<ul>
<li>This way you can keep the least recently used elements in the last and most recently used in front of the cache.</li>
</ul>
</li>
</ul>
<p>Every time a requested page is not found in cache, that is a miss or page fault, and if the page is present in cache, then its a hit.</p>
<h2><a class="anchor" id="autotoc_md97"></a>
Data Structure used</h2>
<ul>
<li>In the algorithm below we used two different data structure, one is linked list and other one is a hash map</li>
<li>The linked list is used to contain the pages and the hash map contains the pages and their address.</li>
<li>Every time a new page is requested, we first check in the hash map if the page is present or not.</li>
<li>If not present, and the cache is full, we simply delete the last entry in the cache.</li>
<li>If present, we shift that page from its current location to beginning of the cache and update the address in hash map for that page.</li>
</ul>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/foo290" target="_blank">Nitin Sharma</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a24d21a345ed06f7fba6919718cf3e058" name="a24d21a345ed06f7fba6919718cf3e058"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a24d21a345ed06f7fba6919718cf3e058">&#9670;&#160;</a></span>log()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T &gt; </div>
<table class="memname">
<tr>
<td class="memname">void lru_tests::log </td>
<td>(</td>
<td class="paramtype">T&#160;</td>
<td class="paramname"><em>msg</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>A function to print given message on console. </p>
<dl class="tparams"><dt>Template Parameters</dt><dd>
<table class="tparams">
<tr><td class="paramname">T</td><td>Type of the given message. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 148</span> {</div>
<div class="line"><span class="lineno"> 149</span> <span class="comment">// It&#39;s just to avoid writing cout and endl</span></div>
<div class="line"><span class="lineno"> 150</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;[TESTS] : ---&gt; &quot;</span> &lt;&lt; msg &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><span class="lineno"> 151</span>}</div>
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(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="../../d3/db3/lru__cache_8cpp_a24d21a345ed06f7fba6919718cf3e058_cgraph.svg" width="228" height="36"><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="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&#160;</a></span>main()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int main </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Main function. </p>
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 251</span> {</div>
<div class="line"><span class="lineno"> 252</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a6a3be6d8871b1f5dc03688da8f3ee9e6">lru_tests::run_tests</a>();</div>
<div class="line"><span class="lineno"> 253</span> </div>
<div class="line"><span class="lineno"> 254</span> <span class="comment">// Usage</span></div>
<div class="line"><span class="lineno"> 255</span> <a class="code hl_class" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html">others::lru_cache::LRUCache</a> cache(4);</div>
<div class="line"><span class="lineno"> 256</span> cache.refer(1);</div>
<div class="line"><span class="lineno"> 257</span> cache.refer(2);</div>
<div class="line"><span class="lineno"> 258</span> cache.refer(3);</div>
<div class="line"><span class="lineno"> 259</span> cache.refer(4);</div>
<div class="line"><span class="lineno"> 260</span> cache.refer(5);</div>
<div class="line"><span class="lineno"> 261</span> cache.refer(5);</div>
<div class="line"><span class="lineno"> 262</span> </div>
<div class="line"><span class="lineno"> 263</span> cache.display();</div>
<div class="line"><span class="lineno"> 264</span> </div>
<div class="line"><span class="lineno"> 265</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Hits: &quot;</span> &lt;&lt; cache.getHits()</div>
<div class="line"><span class="lineno"> 266</span> &lt;&lt; <span class="stringliteral">&quot; Miss: &quot;</span> &lt;&lt; cache.getPageFault() &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><span class="lineno"> 267</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 268</span>}</div>
<div class="ttc" id="aclassothers_1_1lru__cache_1_1_l_r_u_cache_html"><div class="ttname"><a href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html">others::lru_cache::LRUCache</a></div><div class="ttdoc">LRU cache class.</div><div class="ttdef"><b>Definition:</b> lru_cache.cpp:67</div></div>
<div class="ttc" id="alru__cache_8cpp_html_a6a3be6d8871b1f5dc03688da8f3ee9e6"><div class="ttname"><a href="../../d3/db3/lru__cache_8cpp.html#a6a3be6d8871b1f5dc03688da8f3ee9e6">lru_tests::run_tests</a></div><div class="ttdeci">static void run_tests()</div><div class="ttdoc">A function to invoke all test cases.</div><div class="ttdef"><b>Definition:</b> lru_cache.cpp:238</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="../../d3/db3/lru__cache_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="496" height="520"><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="a6a3be6d8871b1f5dc03688da8f3ee9e6" name="a6a3be6d8871b1f5dc03688da8f3ee9e6"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6a3be6d8871b1f5dc03688da8f3ee9e6">&#9670;&#160;</a></span>run_tests()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static void lru_tests::run_tests </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>A function to invoke all test cases. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 238</span> {</div>
<div class="line"><span class="lineno"> 239</span> <a class="code hl_function" href="../../d2/de9/heavy__light__decomposition_8cpp.html#a34b8683a2b429de5cce57e6d733ec817">test_1</a>();</div>
<div class="line"><span class="lineno"> 240</span> <a class="code hl_function" href="../../d2/de9/heavy__light__decomposition_8cpp.html#a458410412185a5f09199deaff7157a8d">test_2</a>();</div>
<div class="line"><span class="lineno"> 241</span> <a class="code hl_function" href="../../d2/de9/heavy__light__decomposition_8cpp.html#af31ec5409537703d9c8a47350386b32a">test_3</a>();</div>
<div class="line"><span class="lineno"> 242</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;&quot;</span>);</div>
<div class="line"><span class="lineno"> 243</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;TESTS COMPLETED!&quot;</span>);</div>
<div class="line"><span class="lineno"> 244</span>}</div>
<div class="ttc" id="aheavy__light__decomposition_8cpp_html_a34b8683a2b429de5cce57e6d733ec817"><div class="ttname"><a href="../../d2/de9/heavy__light__decomposition_8cpp.html#a34b8683a2b429de5cce57e6d733ec817">test_1</a></div><div class="ttdeci">static void test_1()</div><div class="ttdef"><b>Definition:</b> heavy_light_decomposition.cpp:505</div></div>
<div class="ttc" id="aheavy__light__decomposition_8cpp_html_a458410412185a5f09199deaff7157a8d"><div class="ttname"><a href="../../d2/de9/heavy__light__decomposition_8cpp.html#a458410412185a5f09199deaff7157a8d">test_2</a></div><div class="ttdeci">static void test_2()</div><div class="ttdef"><b>Definition:</b> heavy_light_decomposition.cpp:549</div></div>
<div class="ttc" id="aheavy__light__decomposition_8cpp_html_af31ec5409537703d9c8a47350386b32a"><div class="ttname"><a href="../../d2/de9/heavy__light__decomposition_8cpp.html#af31ec5409537703d9c8a47350386b32a">test_3</a></div><div class="ttdeci">static void test_3()</div><div class="ttdef"><b>Definition:</b> heavy_light_decomposition.cpp:592</div></div>
<div class="ttc" id="alog_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/numeric/math/log.html">std::log</a></div><div class="ttdeci">T log(T... args)</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><div class="zoom"><iframe scrolling="no" frameborder="0" src="../../d3/db3/lru__cache_8cpp_a6a3be6d8871b1f5dc03688da8f3ee9e6_cgraph.svg" width="100%" height="600"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div>
</div>
</div>
<a id="a6401e8f2d41d8cc9cd0e52ab381608d4" name="a6401e8f2d41d8cc9cd0e52ab381608d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6401e8f2d41d8cc9cd0e52ab381608d4">&#9670;&#160;</a></span>test_1()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static void lru_tests::test_1 </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>A simple test case The assert statement will check expected hist and miss to resultant hits and miss. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 159</span> {</div>
<div class="line"><span class="lineno"> 160</span> uint64_t expected_hits = 2;</div>
<div class="line"><span class="lineno"> 161</span> uint64_t expected_pageFault = 4;</div>
<div class="line"><span class="lineno"> 162</span> </div>
<div class="line"><span class="lineno"> 163</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Running Test-1...&quot;</span>);</div>
<div class="line"><span class="lineno"> 164</span> </div>
<div class="line"><span class="lineno"> 165</span> <a class="code hl_class" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html">others::lru_cache::LRUCache</a> cache(4);</div>
<div class="line"><span class="lineno"> 166</span> cache.refer(1);</div>
<div class="line"><span class="lineno"> 167</span> cache.refer(2);</div>
<div class="line"><span class="lineno"> 168</span> cache.refer(5);</div>
<div class="line"><span class="lineno"> 169</span> cache.refer(1);</div>
<div class="line"><span class="lineno"> 170</span> cache.refer(4);</div>
<div class="line"><span class="lineno"> 171</span> cache.refer(5);</div>
<div class="line"><span class="lineno"> 172</span> </div>
<div class="line"><span class="lineno"> 173</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Checking assert statement...&quot;</span>);</div>
<div class="line"><span class="lineno"> 174</span> assert(cache.getHits() == expected_hits &amp;&amp;</div>
<div class="line"><span class="lineno"> 175</span> cache.getPageFault() == expected_pageFault);</div>
<div class="line"><span class="lineno"> 176</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Assert successful!&quot;</span>);</div>
<div class="line"><span class="lineno"> 177</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Test-1 complete!&quot;</span>);</div>
<div class="line"><span class="lineno"> 178</span>}</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="../../d3/db3/lru__cache_8cpp_a6401e8f2d41d8cc9cd0e52ab381608d4_cgraph.svg" width="562" height="463"><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="a4b02e288a407876a8d6024f98a2a25ec" name="a4b02e288a407876a8d6024f98a2a25ec"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4b02e288a407876a8d6024f98a2a25ec">&#9670;&#160;</a></span>test_2()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static void lru_tests::test_2 </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>A test case contains hits more than cache size The assert statement will check expected hist and miss to resultant hits and miss. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 186</span> {</div>
<div class="line"><span class="lineno"> 187</span> uint64_t expected_hits = 4;</div>
<div class="line"><span class="lineno"> 188</span> uint64_t expected_pageFault = 2;</div>
<div class="line"><span class="lineno"> 189</span> </div>
<div class="line"><span class="lineno"> 190</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Running Test-2...&quot;</span>);</div>
<div class="line"><span class="lineno"> 191</span> </div>
<div class="line"><span class="lineno"> 192</span> <a class="code hl_class" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html">others::lru_cache::LRUCache</a> cache(4);</div>
<div class="line"><span class="lineno"> 193</span> cache.refer(1);</div>
<div class="line"><span class="lineno"> 194</span> cache.refer(1);</div>
<div class="line"><span class="lineno"> 195</span> cache.refer(1);</div>
<div class="line"><span class="lineno"> 196</span> cache.refer(1);</div>
<div class="line"><span class="lineno"> 197</span> cache.refer(1);</div>
<div class="line"><span class="lineno"> 198</span> cache.refer(5);</div>
<div class="line"><span class="lineno"> 199</span> </div>
<div class="line"><span class="lineno"> 200</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Checking assert statement...&quot;</span>);</div>
<div class="line"><span class="lineno"> 201</span> assert(cache.getHits() == expected_hits &amp;&amp;</div>
<div class="line"><span class="lineno"> 202</span> cache.getPageFault() == expected_pageFault);</div>
<div class="line"><span class="lineno"> 203</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Assert successful!&quot;</span>);</div>
<div class="line"><span class="lineno"> 204</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Test-2 complete!&quot;</span>);</div>
<div class="line"><span class="lineno"> 205</span>}</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="../../d3/db3/lru__cache_8cpp_a4b02e288a407876a8d6024f98a2a25ec_cgraph.svg" width="562" height="463"><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="a01ec21fc91ddafd964ae2035ba7892c0" name="a01ec21fc91ddafd964ae2035ba7892c0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a01ec21fc91ddafd964ae2035ba7892c0">&#9670;&#160;</a></span>test_3()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static void lru_tests::test_3 </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>A simple test case The assert statement will check expected hist and miss to resultant hits and miss. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 213</span> {</div>
<div class="line"><span class="lineno"> 214</span> uint64_t expected_hits = 1;</div>
<div class="line"><span class="lineno"> 215</span> uint64_t expected_pageFault = 5;</div>
<div class="line"><span class="lineno"> 216</span> </div>
<div class="line"><span class="lineno"> 217</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Running Test-3...&quot;</span>);</div>
<div class="line"><span class="lineno"> 218</span> </div>
<div class="line"><span class="lineno"> 219</span> <a class="code hl_class" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html">others::lru_cache::LRUCache</a> cache(4);</div>
<div class="line"><span class="lineno"> 220</span> cache.refer(1);</div>
<div class="line"><span class="lineno"> 221</span> cache.refer(2);</div>
<div class="line"><span class="lineno"> 222</span> cache.refer(3);</div>
<div class="line"><span class="lineno"> 223</span> cache.refer(4);</div>
<div class="line"><span class="lineno"> 224</span> cache.refer(5);</div>
<div class="line"><span class="lineno"> 225</span> cache.refer(5);</div>
<div class="line"><span class="lineno"> 226</span> </div>
<div class="line"><span class="lineno"> 227</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Checking assert statement...&quot;</span>);</div>
<div class="line"><span class="lineno"> 228</span> assert(cache.getHits() == expected_hits &amp;&amp;</div>
<div class="line"><span class="lineno"> 229</span> cache.getPageFault() == expected_pageFault);</div>
<div class="line"><span class="lineno"> 230</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Assert successful!&quot;</span>);</div>
<div class="line"><span class="lineno"> 231</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/log.html">log</a>(<span class="stringliteral">&quot;Test-3 complete!&quot;</span>);</div>
<div class="line"><span class="lineno"> 232</span>}</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="../../d3/db3/lru__cache_8cpp_a01ec21fc91ddafd964ae2035ba7892c0_cgraph.svg" width="562" height="463"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
</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="../../dir_9510827d0b234b3cc54b29892f217477.html">others</a></li><li class="navelem"><a class="el" href="../../d3/db3/lru__cache_8cpp.html">lru_cache.cpp</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.6 </li>
</ul>
</div>
</body>
</html>