mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-22 04:42:10 +08:00
490 lines
38 KiB
HTML
490 lines
38 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">
|
|
<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++: 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 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('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">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#nested-classes">Classes</a> |
|
|
<a href="#namespaces">Namespaces</a> |
|
|
<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 <cassert></code><br />
|
|
<code>#include <iostream></code><br />
|
|
<code>#include <list></code><br />
|
|
<code>#include <unordered_map></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="376" height="112"><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  </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"> </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"> </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  </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"> </td><td class="mdescRight">for <code>vector</code> <br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:d8/dcd/namespacelru__cache"><td class="memItemLeft" align="right" valign="top">namespace  </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"> </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"> </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<typename T > </td></tr>
|
|
<tr class="memitem:a24d21a345ed06f7fba6919718cf3e058"><td class="memTemplItemLeft" align="right" valign="top">void </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"> </td><td class="mdescRight">A function to print given message on console. <a href="../../d3/db3/lru__cache_8cpp.html#a24d21a345ed06f7fba6919718cf3e058">More...</a><br /></td></tr>
|
|
<tr class="separator:a24d21a345ed06f7fba6919718cf3e058"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a6401e8f2d41d8cc9cd0e52ab381608d4"><td class="memItemLeft" align="right" valign="top">static void </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"> </td><td class="mdescRight">A simple test case The assert statement will check expected hist and miss to resultant hits and miss. <a href="../../d3/db3/lru__cache_8cpp.html#a6401e8f2d41d8cc9cd0e52ab381608d4">More...</a><br /></td></tr>
|
|
<tr class="separator:a6401e8f2d41d8cc9cd0e52ab381608d4"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a4b02e288a407876a8d6024f98a2a25ec"><td class="memItemLeft" align="right" valign="top">static void </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"> </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. <a href="../../d3/db3/lru__cache_8cpp.html#a4b02e288a407876a8d6024f98a2a25ec">More...</a><br /></td></tr>
|
|
<tr class="separator:a4b02e288a407876a8d6024f98a2a25ec"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a01ec21fc91ddafd964ae2035ba7892c0"><td class="memItemLeft" align="right" valign="top">static void </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"> </td><td class="mdescRight">A simple test case The assert statement will check expected hist and miss to resultant hits and miss. <a href="../../d3/db3/lru__cache_8cpp.html#a01ec21fc91ddafd964ae2035ba7892c0">More...</a><br /></td></tr>
|
|
<tr class="separator:a01ec21fc91ddafd964ae2035ba7892c0"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a6a3be6d8871b1f5dc03688da8f3ee9e6"><td class="memItemLeft" align="right" valign="top">static void </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"> </td><td class="mdescRight">A function to invoke all test cases. <a href="../../d3/db3/lru__cache_8cpp.html#a6a3be6d8871b1f5dc03688da8f3ee9e6">More...</a><br /></td></tr>
|
|
<tr class="separator:a6a3be6d8871b1f5dc03688da8f3ee9e6"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </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"> </td><td class="mdescRight">Main function. <a href="../../d3/db3/lru__cache_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
|
|
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </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_md89"></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_md90"></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_md91"></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">◆ </a></span>log()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<div class="memtemplate">
|
|
template<typename T > </div>
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void lru_tests::log </td>
|
|
<td>(</td>
|
|
<td class="paramtype">T </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"><a id="l00148" name="l00148"></a><span class="lineno"> 148</span> {</div>
|
|
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno"> 149</span> <span class="comment">// It's just to avoid writing cout and endl</span></div>
|
|
<div class="line"><a id="l00150" name="l00150"></a><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> << <span class="stringliteral">"[TESTS] : ---> "</span> << msg << <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"><a id="l00151" name="l00151"></a><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="38"><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">◆ </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 </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"><a id="l00251" name="l00251"></a><span class="lineno"> 251</span> {</div>
|
|
<div class="line"><a id="l00252" name="l00252"></a><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"><a id="l00253" name="l00253"></a><span class="lineno"> 253</span> </div>
|
|
<div class="line"><a id="l00254" name="l00254"></a><span class="lineno"> 254</span> <span class="comment">// Usage</span></div>
|
|
<div class="line"><a id="l00255" name="l00255"></a><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"><a id="l00256" name="l00256"></a><span class="lineno"> 256</span> cache.refer(1);</div>
|
|
<div class="line"><a id="l00257" name="l00257"></a><span class="lineno"> 257</span> cache.refer(2);</div>
|
|
<div class="line"><a id="l00258" name="l00258"></a><span class="lineno"> 258</span> cache.refer(3);</div>
|
|
<div class="line"><a id="l00259" name="l00259"></a><span class="lineno"> 259</span> cache.refer(4);</div>
|
|
<div class="line"><a id="l00260" name="l00260"></a><span class="lineno"> 260</span> cache.refer(5);</div>
|
|
<div class="line"><a id="l00261" name="l00261"></a><span class="lineno"> 261</span> cache.refer(5);</div>
|
|
<div class="line"><a id="l00262" name="l00262"></a><span class="lineno"> 262</span> </div>
|
|
<div class="line"><a id="l00263" name="l00263"></a><span class="lineno"> 263</span> cache.display();</div>
|
|
<div class="line"><a id="l00264" name="l00264"></a><span class="lineno"> 264</span> </div>
|
|
<div class="line"><a id="l00265" name="l00265"></a><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> << <span class="stringliteral">"Hits: "</span> << cache.getHits()</div>
|
|
<div class="line"><a id="l00266" name="l00266"></a><span class="lineno"> 266</span> << <span class="stringliteral">" Miss: "</span> << cache.getPageFault() << <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"><a id="l00267" name="l00267"></a><span class="lineno"> 267</span> <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a id="l00268" name="l00268"></a><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="403" height="300"><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">◆ </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"><a id="l00238" name="l00238"></a><span class="lineno"> 238</span> {</div>
|
|
<div class="line"><a id="l00239" name="l00239"></a><span class="lineno"> 239</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a6401e8f2d41d8cc9cd0e52ab381608d4">test_1</a>();</div>
|
|
<div class="line"><a id="l00240" name="l00240"></a><span class="lineno"> 240</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a4b02e288a407876a8d6024f98a2a25ec">test_2</a>();</div>
|
|
<div class="line"><a id="l00241" name="l00241"></a><span class="lineno"> 241</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a01ec21fc91ddafd964ae2035ba7892c0">test_3</a>();</div>
|
|
<div class="line"><a id="l00242" name="l00242"></a><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">""</span>);</div>
|
|
<div class="line"><a id="l00243" name="l00243"></a><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">"TESTS COMPLETED!"</span>);</div>
|
|
<div class="line"><a id="l00244" name="l00244"></a><span class="lineno"> 244</span>}</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 class="ttc" id="alru__cache_8cpp_html_a01ec21fc91ddafd964ae2035ba7892c0"><div class="ttname"><a href="../../d3/db3/lru__cache_8cpp.html#a01ec21fc91ddafd964ae2035ba7892c0">lru_tests::test_3</a></div><div class="ttdeci">static void test_3()</div><div class="ttdoc">A simple test case The assert statement will check expected hist and miss to resultant hits and miss.</div><div class="ttdef"><b>Definition:</b> lru_cache.cpp:213</div></div>
|
|
<div class="ttc" id="alru__cache_8cpp_html_a4b02e288a407876a8d6024f98a2a25ec"><div class="ttname"><a href="../../d3/db3/lru__cache_8cpp.html#a4b02e288a407876a8d6024f98a2a25ec">lru_tests::test_2</a></div><div class="ttdeci">static void test_2()</div><div class="ttdoc">A test case contains hits more than cache size The assert statement will check expected hist and miss...</div><div class="ttdef"><b>Definition:</b> lru_cache.cpp:186</div></div>
|
|
<div class="ttc" id="alru__cache_8cpp_html_a6401e8f2d41d8cc9cd0e52ab381608d4"><div class="ttname"><a href="../../d3/db3/lru__cache_8cpp.html#a6401e8f2d41d8cc9cd0e52ab381608d4">lru_tests::test_1</a></div><div class="ttdeci">static void test_1()</div><div class="ttdoc">A simple test case The assert statement will check expected hist and miss to resultant hits and miss.</div><div class="ttdef"><b>Definition:</b> lru_cache.cpp:159</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_a6a3be6d8871b1f5dc03688da8f3ee9e6_cgraph.svg" width="531" height="211"><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="a6401e8f2d41d8cc9cd0e52ab381608d4" name="a6401e8f2d41d8cc9cd0e52ab381608d4"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a6401e8f2d41d8cc9cd0e52ab381608d4">◆ </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"><a id="l00159" name="l00159"></a><span class="lineno"> 159</span> {</div>
|
|
<div class="line"><a id="l00160" name="l00160"></a><span class="lineno"> 160</span> uint64_t expected_hits = 2;</div>
|
|
<div class="line"><a id="l00161" name="l00161"></a><span class="lineno"> 161</span> uint64_t expected_pageFault = 4;</div>
|
|
<div class="line"><a id="l00162" name="l00162"></a><span class="lineno"> 162</span> </div>
|
|
<div class="line"><a id="l00163" name="l00163"></a><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">"Running Test-1..."</span>);</div>
|
|
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno"> 164</span> </div>
|
|
<div class="line"><a id="l00165" name="l00165"></a><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"><a id="l00166" name="l00166"></a><span class="lineno"> 166</span> cache.refer(1);</div>
|
|
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno"> 167</span> cache.refer(2);</div>
|
|
<div class="line"><a id="l00168" name="l00168"></a><span class="lineno"> 168</span> cache.refer(5);</div>
|
|
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno"> 169</span> cache.refer(1);</div>
|
|
<div class="line"><a id="l00170" name="l00170"></a><span class="lineno"> 170</span> cache.refer(4);</div>
|
|
<div class="line"><a id="l00171" name="l00171"></a><span class="lineno"> 171</span> cache.refer(5);</div>
|
|
<div class="line"><a id="l00172" name="l00172"></a><span class="lineno"> 172</span> </div>
|
|
<div class="line"><a id="l00173" name="l00173"></a><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">"Checking assert statement..."</span>);</div>
|
|
<div class="line"><a id="l00174" name="l00174"></a><span class="lineno"> 174</span> assert(cache.getHits() == expected_hits &&</div>
|
|
<div class="line"><a id="l00175" name="l00175"></a><span class="lineno"> 175</span> cache.getPageFault() == expected_pageFault);</div>
|
|
<div class="line"><a id="l00176" name="l00176"></a><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">"Assert successful!"</span>);</div>
|
|
<div class="line"><a id="l00177" name="l00177"></a><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">"Test-1 complete!"</span>);</div>
|
|
<div class="line"><a id="l00178" name="l00178"></a><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="348" height="183"><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">◆ </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"><a id="l00186" name="l00186"></a><span class="lineno"> 186</span> {</div>
|
|
<div class="line"><a id="l00187" name="l00187"></a><span class="lineno"> 187</span> uint64_t expected_hits = 4;</div>
|
|
<div class="line"><a id="l00188" name="l00188"></a><span class="lineno"> 188</span> uint64_t expected_pageFault = 2;</div>
|
|
<div class="line"><a id="l00189" name="l00189"></a><span class="lineno"> 189</span> </div>
|
|
<div class="line"><a id="l00190" name="l00190"></a><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">"Running Test-2..."</span>);</div>
|
|
<div class="line"><a id="l00191" name="l00191"></a><span class="lineno"> 191</span> </div>
|
|
<div class="line"><a id="l00192" name="l00192"></a><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"><a id="l00193" name="l00193"></a><span class="lineno"> 193</span> cache.refer(1);</div>
|
|
<div class="line"><a id="l00194" name="l00194"></a><span class="lineno"> 194</span> cache.refer(1);</div>
|
|
<div class="line"><a id="l00195" name="l00195"></a><span class="lineno"> 195</span> cache.refer(1);</div>
|
|
<div class="line"><a id="l00196" name="l00196"></a><span class="lineno"> 196</span> cache.refer(1);</div>
|
|
<div class="line"><a id="l00197" name="l00197"></a><span class="lineno"> 197</span> cache.refer(1);</div>
|
|
<div class="line"><a id="l00198" name="l00198"></a><span class="lineno"> 198</span> cache.refer(5);</div>
|
|
<div class="line"><a id="l00199" name="l00199"></a><span class="lineno"> 199</span> </div>
|
|
<div class="line"><a id="l00200" name="l00200"></a><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">"Checking assert statement..."</span>);</div>
|
|
<div class="line"><a id="l00201" name="l00201"></a><span class="lineno"> 201</span> assert(cache.getHits() == expected_hits &&</div>
|
|
<div class="line"><a id="l00202" name="l00202"></a><span class="lineno"> 202</span> cache.getPageFault() == expected_pageFault);</div>
|
|
<div class="line"><a id="l00203" name="l00203"></a><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">"Assert successful!"</span>);</div>
|
|
<div class="line"><a id="l00204" name="l00204"></a><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">"Test-2 complete!"</span>);</div>
|
|
<div class="line"><a id="l00205" name="l00205"></a><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="348" height="183"><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">◆ </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"><a id="l00213" name="l00213"></a><span class="lineno"> 213</span> {</div>
|
|
<div class="line"><a id="l00214" name="l00214"></a><span class="lineno"> 214</span> uint64_t expected_hits = 1;</div>
|
|
<div class="line"><a id="l00215" name="l00215"></a><span class="lineno"> 215</span> uint64_t expected_pageFault = 5;</div>
|
|
<div class="line"><a id="l00216" name="l00216"></a><span class="lineno"> 216</span> </div>
|
|
<div class="line"><a id="l00217" name="l00217"></a><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">"Running Test-3..."</span>);</div>
|
|
<div class="line"><a id="l00218" name="l00218"></a><span class="lineno"> 218</span> </div>
|
|
<div class="line"><a id="l00219" name="l00219"></a><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"><a id="l00220" name="l00220"></a><span class="lineno"> 220</span> cache.refer(1);</div>
|
|
<div class="line"><a id="l00221" name="l00221"></a><span class="lineno"> 221</span> cache.refer(2);</div>
|
|
<div class="line"><a id="l00222" name="l00222"></a><span class="lineno"> 222</span> cache.refer(3);</div>
|
|
<div class="line"><a id="l00223" name="l00223"></a><span class="lineno"> 223</span> cache.refer(4);</div>
|
|
<div class="line"><a id="l00224" name="l00224"></a><span class="lineno"> 224</span> cache.refer(5);</div>
|
|
<div class="line"><a id="l00225" name="l00225"></a><span class="lineno"> 225</span> cache.refer(5);</div>
|
|
<div class="line"><a id="l00226" name="l00226"></a><span class="lineno"> 226</span> </div>
|
|
<div class="line"><a id="l00227" name="l00227"></a><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">"Checking assert statement..."</span>);</div>
|
|
<div class="line"><a id="l00228" name="l00228"></a><span class="lineno"> 228</span> assert(cache.getHits() == expected_hits &&</div>
|
|
<div class="line"><a id="l00229" name="l00229"></a><span class="lineno"> 229</span> cache.getPageFault() == expected_pageFault);</div>
|
|
<div class="line"><a id="l00230" name="l00230"></a><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">"Assert successful!"</span>);</div>
|
|
<div class="line"><a id="l00231" name="l00231"></a><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">"Test-3 complete!"</span>);</div>
|
|
<div class="line"><a id="l00232" name="l00232"></a><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="348" height="183"><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.2 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|