Documentation for c26eea874d

This commit is contained in:
realstealthninja
2025-05-19 11:38:33 +00:00
parent c7a9a42397
commit 14583a2f33
2829 changed files with 30266 additions and 21669 deletions

View File

@@ -4,7 +4,7 @@
<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.12.0"/>
<meta name="generator" content="Doxygen 1.13.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>TheAlgorithms/C++: others/lru_cache.cpp Source File</title>
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
@@ -60,7 +60,7 @@ window.MathJax = {
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.12.0 -->
<!-- Generated by Doxygen 1.13.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
@@ -124,17 +124,18 @@ $(function(){initNavTree('d3/db3/lru__cache_8cpp_source.html','../../'); initRes
<div class="headertitle"><div class="title">lru_cache.cpp</div></div>
</div><!--header-->
<div class="contents">
<a href="../../d3/db3/lru__cache_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span> </div>
<a href="../../d3/db3/lru__cache_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span></div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> </div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span><span class="preprocessor">#include &lt;cassert&gt;</span> </div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span><span class="preprocessor">#include &lt;cstdint&gt;</span></div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span><span class="preprocessor">#include &lt;iostream&gt;</span> </div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"> 51</span><span class="preprocessor">#include &lt;list&gt;</span> </div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span><span class="preprocessor">#include &lt;unordered_map&gt;</span> </div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> </div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span></div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../d0/d6f/namespaceothers.html">others</a> {</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../d8/dcd/namespacelru__cache.html">lru_cache</a> {</div>
<div class="foldopen" id="foldopen00068" data-start="{" data-end="};">
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"><a class="line" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html"> 68</a></span><span class="keyword">class </span><a class="code hl_class" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html">LRUCache</a> {</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"><a class="line" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html"> 68</a></span><span class="keyword">class </span><a class="code hl_function" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a41c9b6f1693b8a316cc4a2d8c9149ba4">LRUCache</a> {</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"><a class="line" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a1aafd0444b410e0fcb66287e9954c893"> 69</a></span> uint64_t <a class="code hl_variable" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a1aafd0444b410e0fcb66287e9954c893">pageFrame</a>; </div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"><a class="line" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a3ee3560a6b90e6f50f6e063d690ba8e8"> 70</a></span> std::list&lt;uint64_t&gt; <a class="code hl_variable" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a3ee3560a6b90e6f50f6e063d690ba8e8">cache</a>; </div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> std::unordered_map&lt;uint64_t, std::list&lt;uint64_t&gt;::iterator&gt;</div>
@@ -146,7 +147,7 @@ $(function(){initNavTree('d3/db3/lru__cache_8cpp_source.html','../../'); initRes
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> </div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"><a class="line" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a41c9b6f1693b8a316cc4a2d8c9149ba4"> 85</a></span> <span class="keyword">explicit</span> <a class="code hl_function" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a41c9b6f1693b8a316cc4a2d8c9149ba4">LRUCache</a>(uint64_t pf) { <a class="code hl_variable" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a1aafd0444b410e0fcb66287e9954c893">pageFrame</a> = pf; }</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> </div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span></div>
<div class="foldopen" id="foldopen00092" data-start="{" data-end="}">
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"><a class="line" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a7dbf04bf7e1472c48639694f0b110602"> 92</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a7dbf04bf7e1472c48639694f0b110602">refer</a>(uint64_t page) {</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> <span class="comment">// If the page requested not in cache.</span></div>
@@ -173,7 +174,7 @@ $(function(){initNavTree('d3/db3/lru__cache_8cpp_source.html','../../'); initRes
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> <a class="code hl_variable" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#aa4d6db56109af196ffc7e5f72bc9907c">pageMap</a>[page] = <a class="code hl_variable" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a3ee3560a6b90e6f50f6e063d690ba8e8">cache</a>.begin();</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> }</div>
</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> </div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span></div>
<div class="foldopen" id="foldopen00121" data-start="{" data-end="}">
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"><a class="line" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#aad506b1c1a3cd5b93cc7e497626bfb53"> 121</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#aad506b1c1a3cd5b93cc7e497626bfb53">display</a>() {</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span> <span class="keywordflow">for</span> (uint64_t &amp;it : <a class="code hl_variable" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a3ee3560a6b90e6f50f6e063d690ba8e8">cache</a>) {</div>
@@ -182,6 +183,7 @@ $(function(){initNavTree('d3/db3/lru__cache_8cpp_source.html','../../'); initRes
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno"> 125</span> std::cout &lt;&lt; std::endl;</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno"> 126</span> }</div>
</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno"> 127</span></div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno"><a class="line" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#aa24a141455b9fbcbec22392c28d04933"> 131</a></span> uint64_t <a class="code hl_function" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#aa24a141455b9fbcbec22392c28d04933">getHits</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code hl_variable" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a5f33913e7ddfbb38062362e7bd859154">hits</a>; }</div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno"><a class="line" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a78be932dac71c90f485a67d4fda877e2"> 136</a></span> uint64_t <a class="code hl_function" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a78be932dac71c90f485a67d4fda877e2">getPageFault</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code hl_variable" href="../../d6/dae/classothers_1_1lru__cache_1_1_l_r_u_cache.html#a09cbe562b0c396329607f5d388d57c9c">pageFault</a>; }</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno"> 137</span>};</div>
@@ -198,7 +200,7 @@ $(function(){initNavTree('d3/db3/lru__cache_8cpp_source.html','../../'); initRes
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno"> 151</span> std::cout &lt;&lt; <span class="stringliteral">&quot;[TESTS] : ---&gt; &quot;</span> &lt;&lt; msg &lt;&lt; std::endl;</div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno"> 152</span>}</div>
</div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno"> 153</span> </div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno"> 153</span></div>
<div class="foldopen" id="foldopen00160" data-start="{" data-end="}">
<div class="line"><a id="l00160" name="l00160"></a><span class="lineno"><a class="line" href="../../d3/db3/lru__cache_8cpp.html#a6401e8f2d41d8cc9cd0e52ab381608d4"> 160</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a6401e8f2d41d8cc9cd0e52ab381608d4">test_1</a>() {</div>
<div class="line"><a id="l00161" name="l00161"></a><span class="lineno"> 161</span> uint64_t expected_hits = 2;</div>
@@ -221,7 +223,7 @@ $(function(){initNavTree('d3/db3/lru__cache_8cpp_source.html','../../'); initRes
<div class="line"><a id="l00178" name="l00178"></a><span class="lineno"> 178</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a24d21a345ed06f7fba6919718cf3e058">log</a>(<span class="stringliteral">&quot;Test-1 complete!&quot;</span>);</div>
<div class="line"><a id="l00179" name="l00179"></a><span class="lineno"> 179</span>}</div>
</div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno"> 180</span> </div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno"> 180</span></div>
<div class="foldopen" id="foldopen00187" data-start="{" data-end="}">
<div class="line"><a id="l00187" name="l00187"></a><span class="lineno"><a class="line" href="../../d3/db3/lru__cache_8cpp.html#a4b02e288a407876a8d6024f98a2a25ec"> 187</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a4b02e288a407876a8d6024f98a2a25ec">test_2</a>() {</div>
<div class="line"><a id="l00188" name="l00188"></a><span class="lineno"> 188</span> uint64_t expected_hits = 4;</div>
@@ -244,7 +246,7 @@ $(function(){initNavTree('d3/db3/lru__cache_8cpp_source.html','../../'); initRes
<div class="line"><a id="l00205" name="l00205"></a><span class="lineno"> 205</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a24d21a345ed06f7fba6919718cf3e058">log</a>(<span class="stringliteral">&quot;Test-2 complete!&quot;</span>);</div>
<div class="line"><a id="l00206" name="l00206"></a><span class="lineno"> 206</span>}</div>
</div>
<div class="line"><a id="l00207" name="l00207"></a><span class="lineno"> 207</span> </div>
<div class="line"><a id="l00207" name="l00207"></a><span class="lineno"> 207</span></div>
<div class="foldopen" id="foldopen00214" data-start="{" data-end="}">
<div class="line"><a id="l00214" name="l00214"></a><span class="lineno"><a class="line" href="../../d3/db3/lru__cache_8cpp.html#a01ec21fc91ddafd964ae2035ba7892c0"> 214</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a01ec21fc91ddafd964ae2035ba7892c0">test_3</a>() {</div>
<div class="line"><a id="l00215" name="l00215"></a><span class="lineno"> 215</span> uint64_t expected_hits = 1;</div>
@@ -267,7 +269,7 @@ $(function(){initNavTree('d3/db3/lru__cache_8cpp_source.html','../../'); initRes
<div class="line"><a id="l00232" name="l00232"></a><span class="lineno"> 232</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a24d21a345ed06f7fba6919718cf3e058">log</a>(<span class="stringliteral">&quot;Test-3 complete!&quot;</span>);</div>
<div class="line"><a id="l00233" name="l00233"></a><span class="lineno"> 233</span>}</div>
</div>
<div class="line"><a id="l00234" name="l00234"></a><span class="lineno"> 234</span> </div>
<div class="line"><a id="l00234" name="l00234"></a><span class="lineno"> 234</span></div>
<div class="foldopen" id="foldopen00239" data-start="{" data-end="}">
<div class="line"><a id="l00239" name="l00239"></a><span class="lineno"><a class="line" href="../../d3/db3/lru__cache_8cpp.html#a6a3be6d8871b1f5dc03688da8f3ee9e6"> 239</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#a6a3be6d8871b1f5dc03688da8f3ee9e6">run_tests</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#a6401e8f2d41d8cc9cd0e52ab381608d4">test_1</a>();</div>
@@ -278,10 +280,10 @@ $(function(){initNavTree('d3/db3/lru__cache_8cpp_source.html','../../'); initRes
<div class="line"><a id="l00245" name="l00245"></a><span class="lineno"> 245</span>}</div>
</div>
<div class="line"><a id="l00246" name="l00246"></a><span class="lineno"> 246</span>} <span class="comment">// namespace lru_tests</span></div>
<div class="line"><a id="l00247" name="l00247"></a><span class="lineno"> 247</span> </div>
<div class="line"><a id="l00247" name="l00247"></a><span class="lineno"> 247</span></div>
<div class="foldopen" id="foldopen00252" data-start="{" data-end="}">
<div class="line"><a id="l00252" name="l00252"></a><span class="lineno"><a class="line" href="../../d3/db3/lru__cache_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4"> 252</a></span><span class="keywordtype">int</span> <a class="code hl_function" href="../../d3/db3/lru__cache_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a>() {</div>
<div class="line"><a id="l00253" name="l00253"></a><span class="lineno"> 253</span> lru_tests::run_tests();</div>
<div class="line"><a id="l00253" name="l00253"></a><span class="lineno"> 253</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="l00254" name="l00254"></a><span class="lineno"> 254</span> </div>
<div class="line"><a id="l00255" name="l00255"></a><span class="lineno"> 255</span> <span class="comment">// Usage</span></div>
<div class="line"><a id="l00256" name="l00256"></a><span class="lineno"> 256</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>
@@ -324,7 +326,7 @@ $(function(){initNavTree('d3/db3/lru__cache_8cpp_source.html','../../'); initRes
<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.12.0 </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.13.2 </li>
</ul>
</div>
</body>