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++: strings/knuth_morris_pratt.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,12 +124,13 @@ $(function(){initNavTree('de/d6a/knuth__morris__pratt_8cpp_source.html','../../'
<div class="headertitle"><div class="title">knuth_morris_pratt.cpp</div></div>
</div><!--header-->
<div class="contents">
<a href="../../de/d6a/knuth__morris__pratt_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="../../de/d6a/knuth__morris__pratt_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="l00015" name="l00015"></a><span class="lineno"> 15</span> </div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span><span class="preprocessor">#include &lt;cassert&gt;</span> </div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span><span class="preprocessor">#include &lt;iostream&gt;</span> </div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"> 18</span><span class="preprocessor">#include &lt;string&gt;</span> </div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span><span class="preprocessor">#include &lt;vector&gt;</span> </div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span> </div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span></div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../d9/d03/namespacestring__search.html">string_search</a> {</div>
<div class="foldopen" id="foldopen00032" data-start="{" data-end="}">
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"><a class="line" href="../../d9/d03/namespacestring__search.html#a83c72ff237cdf623e42d4295e0029bf9"> 32</a></span>std::vector&lt;size_t&gt; <a class="code hl_function" href="../../d9/d03/namespacestring__search.html#a83c72ff237cdf623e42d4295e0029bf9">getFailureArray</a>(<span class="keyword">const</span> std::string &amp;pattern) {</div>
@@ -146,7 +147,7 @@ $(function(){initNavTree('de/d6a/knuth__morris__pratt_8cpp_source.html','../../'
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> <span class="keywordflow">return</span> failure;</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span>}</div>
</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> </div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span></div>
<div class="foldopen" id="foldopen00053" data-start="{" data-end="}">
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"><a class="line" href="../../d9/d03/namespacestring__search.html#a1e37af2f023495129cb57338c801209e"> 53</a></span><span class="keywordtype">size_t</span> <a class="code hl_function" href="../../d9/d03/namespacestring__search.html#a1e37af2f023495129cb57338c801209e">kmp</a>(<span class="keyword">const</span> std::string &amp;pattern, <span class="keyword">const</span> std::string &amp;text) {</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> <span class="keywordflow">if</span> (pattern.empty()) {</div>
@@ -170,15 +171,15 @@ $(function(){initNavTree('de/d6a/knuth__morris__pratt_8cpp_source.html','../../'
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span>} <span class="comment">// namespace string_search</span></div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> </div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span><span class="keyword">using </span><a class="code hl_function" href="../../d9/d03/namespacestring__search.html#a1e37af2f023495129cb57338c801209e">string_search::kmp</a>;</div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> </div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span></div>
<div class="foldopen" id="foldopen00079" data-start="{" data-end="}">
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"><a class="line" href="../../de/d6a/knuth__morris__pratt_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e"> 79</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../de/d6a/knuth__morris__pratt_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a>() {</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> assert(kmp(<span class="stringliteral">&quot;abc1abc12l&quot;</span>, <span class="stringliteral">&quot;alskfjaldsabc1abc1abc12k2&quot;</span>) == std::string::npos);</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> assert(kmp(<span class="stringliteral">&quot;bca&quot;</span>, <span class="stringliteral">&quot;abcabc&quot;</span>) == 1);</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> assert(kmp(<span class="stringliteral">&quot;World&quot;</span>, <span class="stringliteral">&quot;helloWorld&quot;</span>) == 5);</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> assert(kmp(<span class="stringliteral">&quot;c++&quot;</span>, <span class="stringliteral">&quot;his_is_c++&quot;</span>) == 7);</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> assert(kmp(<span class="stringliteral">&quot;happy&quot;</span>, <span class="stringliteral">&quot;happy_coding&quot;</span>) == 0);</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> assert(kmp(<span class="stringliteral">&quot;&quot;</span>, <span class="stringliteral">&quot;pattern is empty&quot;</span>) == 0);</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> assert(<a class="code hl_function" href="../../de/d6a/knuth__morris__pratt_8cpp.html#a1e37af2f023495129cb57338c801209e">kmp</a>(<span class="stringliteral">&quot;abc1abc12l&quot;</span>, <span class="stringliteral">&quot;alskfjaldsabc1abc1abc12k2&quot;</span>) == std::string::npos);</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> assert(<a class="code hl_function" href="../../de/d6a/knuth__morris__pratt_8cpp.html#a1e37af2f023495129cb57338c801209e">kmp</a>(<span class="stringliteral">&quot;bca&quot;</span>, <span class="stringliteral">&quot;abcabc&quot;</span>) == 1);</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> assert(<a class="code hl_function" href="../../de/d6a/knuth__morris__pratt_8cpp.html#a1e37af2f023495129cb57338c801209e">kmp</a>(<span class="stringliteral">&quot;World&quot;</span>, <span class="stringliteral">&quot;helloWorld&quot;</span>) == 5);</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> assert(<a class="code hl_function" href="../../de/d6a/knuth__morris__pratt_8cpp.html#a1e37af2f023495129cb57338c801209e">kmp</a>(<span class="stringliteral">&quot;c++&quot;</span>, <span class="stringliteral">&quot;his_is_c++&quot;</span>) == 7);</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> assert(<a class="code hl_function" href="../../de/d6a/knuth__morris__pratt_8cpp.html#a1e37af2f023495129cb57338c801209e">kmp</a>(<span class="stringliteral">&quot;happy&quot;</span>, <span class="stringliteral">&quot;happy_coding&quot;</span>) == 0);</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> assert(<a class="code hl_function" href="../../de/d6a/knuth__morris__pratt_8cpp.html#a1e37af2f023495129cb57338c801209e">kmp</a>(<span class="stringliteral">&quot;&quot;</span>, <span class="stringliteral">&quot;pattern is empty&quot;</span>) == 0);</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> </div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> <span class="comment">// this lets the user know that the tests have passed</span></div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> std::cout &lt;&lt; <span class="stringliteral">&quot;All KMP algorithm tests have successfully passed!\n&quot;</span>;</div>
@@ -194,6 +195,7 @@ $(function(){initNavTree('de/d6a/knuth__morris__pratt_8cpp_source.html','../../'
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span>}</div>
<div class="ttc" id="agenerate__parentheses_8cpp_html_gae66f6b31b5ad750f1fe042a706a4e3d4"><div class="ttname"><a href="../../dd/d1e/generate__parentheses_8cpp.html#gae66f6b31b5ad750f1fe042a706a4e3d4">main</a></div><div class="ttdeci">int main()</div><div class="ttdoc">Main function.</div><div class="ttdef"><b>Definition</b> <a href="../../dd/d1e/generate__parentheses_8cpp_source.html#l00110">generate_parentheses.cpp:110</a></div></div>
<div class="ttc" id="aknuth__morris__pratt_8cpp_html_a1e37af2f023495129cb57338c801209e"><div class="ttname"><a href="../../de/d6a/knuth__morris__pratt_8cpp.html#a1e37af2f023495129cb57338c801209e">kmp</a></div><div class="ttdeci">size_t kmp(const std::string &amp;pattern, const std::string &amp;text)</div><div class="ttdoc">KMP algorithm to find a pattern in a text.</div><div class="ttdef"><b>Definition</b> <a href="#l00053">knuth_morris_pratt.cpp:53</a></div></div>
<div class="ttc" id="aknuth__morris__pratt_8cpp_html_a483bb8ccf42aaf7375a83e91490eda1e"><div class="ttname"><a href="../../de/d6a/knuth__morris__pratt_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a></div><div class="ttdeci">static void tests()</div><div class="ttdoc">self-test implementations</div><div class="ttdef"><b>Definition</b> <a href="#l00079">knuth_morris_pratt.cpp:79</a></div></div>
<div class="ttc" id="anamespacestring__search_html"><div class="ttname"><a href="../../d9/d03/namespacestring__search.html">string_search</a></div><div class="ttdoc">String search algorithms.</div><div class="ttdef"><b>Definition</b> <a href="../../d3/d7d/brute__force__string__searching_8cpp_source.html#l00013">brute_force_string_searching.cpp:13</a></div></div>
<div class="ttc" id="anamespacestring__search_html_a1e37af2f023495129cb57338c801209e"><div class="ttname"><a href="../../d9/d03/namespacestring__search.html#a1e37af2f023495129cb57338c801209e">string_search::kmp</a></div><div class="ttdeci">size_t kmp(const std::string &amp;pattern, const std::string &amp;text)</div><div class="ttdoc">KMP algorithm to find a pattern in a text.</div><div class="ttdef"><b>Definition</b> <a href="#l00053">knuth_morris_pratt.cpp:53</a></div></div>
@@ -204,7 +206,7 @@ $(function(){initNavTree('de/d6a/knuth__morris__pratt_8cpp_source.html','../../'
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_73a3cc5065b223eb41b02873c0e19f0e.html">strings</a></li><li class="navelem"><a class="el" href="../../de/d6a/knuth__morris__pratt_8cpp.html">knuth_morris_pratt.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>