Files
C-Plus-Plus/d3/d39/manacher__algorithm_8cpp.html
2024-11-04 12:10:37 +00:00

383 lines
32 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.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: strings/manacher_algorithm.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>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../cookie.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.12.0 -->
<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">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(1); });
/* @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',true);
$(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 */
$(function(){initNavTree('d3/d39/manacher__algorithm_8cpp.html','../../'); initResizable(true); });
/* @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="#namespaces">Namespaces</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle"><div class="title">manacher_algorithm.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
<p>Implementation of <a href="https://en.wikipedia.org/wiki/Longest_palindromic_substring" target="_blank">Manacher's Algorithm</a>
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;cassert&gt;</code><br />
<code>#include &lt;cstdint&gt;</code><br />
<code>#include &lt;iostream&gt;</code><br />
<code>#include &lt;vector&gt;</code><br />
<code>#include &lt;cstring&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for manacher_algorithm.cpp:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dd/d05/manacher__algorithm_8cpp__incl.svg" width="420" height="111"><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="namespaces" name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/dcb/namespacestrings.html">strings</a></td></tr>
<tr class="memdesc:df/dcb/namespacestrings"><td class="mdescLeft">&#160;</td><td class="mdescRight">String algorithms. <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d8/dc6/namespacemanacher.html">manacher</a></td></tr>
<tr class="memdesc:d8/dc6/namespacemanacher"><td class="mdescLeft">&#160;</td><td class="mdescRight">Functions for <a href="https://en.wikipedia.org/wiki/Longest_palindromic_substring" target="_blank">Manacher's Algorithm</a> implementation. <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:a95e6a2976bb2f332898f373941d52098" id="r_a95e6a2976bb2f332898f373941d52098"><td class="memItemLeft" align="right" valign="top"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a95e6a2976bb2f332898f373941d52098">strings::manacher::manacher</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> &amp;prototype)</td></tr>
<tr class="memdesc:a95e6a2976bb2f332898f373941d52098"><td class="mdescLeft">&#160;</td><td class="mdescRight">A function that implements Manacher's algorithm. <br /></td></tr>
<tr class="separator:a95e6a2976bb2f332898f373941d52098"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d" id="r_aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Self-test implementations. <br /></td></tr>
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4" id="r_ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#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>Implementation of <a href="https://en.wikipedia.org/wiki/Longest_palindromic_substring" target="_blank">Manacher's Algorithm</a> </p>
<p>Manacher's Algorithm is used to find the longest palindromic substring within a string in O(n) time. It exploits the property of a palindrome that its first half is symmetric to the last half, and thus if the first half is a palindrome, then last half is also a palindrome. </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/riti2409" target="_blank">Riti Kumari</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<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</td> <td class="paramname"><span class="paramname"><em></em></span></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"> 172</span> {</div>
<div class="line"><span class="lineno"> 173</span> <a class="code hl_function" href="#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
<div class="line"><span class="lineno"> 174</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 175</span>}</div>
<div class="ttc" id="amanacher__algorithm_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition</b> manacher_algorithm.cpp:151</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/d39/manacher__algorithm_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="271" 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="a95e6a2976bb2f332898f373941d52098" name="a95e6a2976bb2f332898f373941d52098"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a95e6a2976bb2f332898f373941d52098">&#9670;&#160;</a></span>manacher()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> strings::manacher::manacher </td>
<td>(</td>
<td class="paramtype">const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> &amp;</td> <td class="paramname"><span class="paramname"><em>prototype</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>A function that implements Manacher's algorithm. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">prototype</td><td>is the string where algorithm finds a palindromic substring. This string can contain any character except <code>@</code> <code>#</code> <code>&amp;</code> </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the largest palindromic substring </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 41</span> {</div>
<div class="line"><span class="lineno"> 42</span> <span class="keywordflow">if</span> (prototype.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">size</a>() &gt; 0) {</div>
<div class="line"><span class="lineno"> 43</span> <span class="comment">// stuffing characters between the input string to handle cases with</span></div>
<div class="line"><span class="lineno"> 44</span> <span class="comment">// even length palindrome</span></div>
<div class="line"><span class="lineno"> 45</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> stuffed_string = <span class="stringliteral">&quot;&quot;</span>;</div>
<div class="line"><span class="lineno"> 46</span> <span class="keywordflow">for</span> (<span class="keyword">auto</span> str : prototype) {</div>
<div class="line"><span class="lineno"> 47</span> stuffed_string += str;</div>
<div class="line"><span class="lineno"> 48</span> stuffed_string += <span class="stringliteral">&quot;#&quot;</span>;</div>
<div class="line"><span class="lineno"> 49</span> }</div>
<div class="line"><span class="lineno"> 50</span> stuffed_string = <span class="stringliteral">&quot;@#&quot;</span> + stuffed_string + <span class="stringliteral">&quot;&amp;&quot;</span>;</div>
<div class="line"><span class="lineno"> 51</span> </div>
<div class="line"><span class="lineno"> 52</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;uint64_t&gt;</a> palindrome_max_half_length(</div>
<div class="line"><span class="lineno"> 53</span> stuffed_string.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">size</a>(),</div>
<div class="line"><span class="lineno"> 54</span> 0); <span class="comment">// this array will consist of largest possible half length of</span></div>
<div class="line"><span class="lineno"> 55</span> <span class="comment">// palindrome centered at index (say i with respect to the</span></div>
<div class="line"><span class="lineno"> 56</span> <span class="comment">// stuffed string). This value will be lower bound of half</span></div>
<div class="line"><span class="lineno"> 57</span> <span class="comment">// length since single character is a palindrome in itself.</span></div>
<div class="line"><span class="lineno"> 58</span> </div>
<div class="line"><span class="lineno"> 59</span> uint64_t bigger_center =</div>
<div class="line"><span class="lineno"> 60</span> 0; <span class="comment">// this is the index of the center of palindromic</span></div>
<div class="line"><span class="lineno"> 61</span> <span class="comment">// substring which would be considered as the larger</span></div>
<div class="line"><span class="lineno"> 62</span> <span class="comment">// palindrome, having symmetric halves</span></div>
<div class="line"><span class="lineno"> 63</span> </div>
<div class="line"><span class="lineno"> 64</span> uint64_t <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/left.html">right</a> = 0; <span class="comment">// this is the maximum length of the palindrome</span></div>
<div class="line"><span class="lineno"> 65</span> <span class="comment">// from &#39;bigger_center&#39; to the rightmost end</span></div>
<div class="line"><span class="lineno"> 66</span> </div>
<div class="line"><span class="lineno"> 67</span> <span class="comment">// i is considered as center lying within one half of the palindrone</span></div>
<div class="line"><span class="lineno"> 68</span> <span class="comment">// which is centered at &#39;bigger_center&#39;</span></div>
<div class="line"><span class="lineno"> 69</span> <span class="keywordflow">for</span> (uint64_t i = 1; i &lt; stuffed_string.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">size</a>() - 1; i++) {</div>
<div class="line"><span class="lineno"> 70</span> <span class="keywordflow">if</span> (i &lt; right) { <span class="comment">// when i is before right end, considering</span></div>
<div class="line"><span class="lineno"> 71</span> <span class="comment">// &#39;bigger_center&#39; as center of palindrome</span></div>
<div class="line"><span class="lineno"> 72</span> uint64_t opposite_to_i =</div>
<div class="line"><span class="lineno"> 73</span> 2 * bigger_center -</div>
<div class="line"><span class="lineno"> 74</span> i; <span class="comment">// this is the opposite end of string, if</span></div>
<div class="line"><span class="lineno"> 75</span> <span class="comment">// centered at center, and having one end as i</span></div>
<div class="line"><span class="lineno"> 76</span> </div>
<div class="line"><span class="lineno"> 77</span> <span class="comment">// finding the minimum possible half length among</span></div>
<div class="line"><span class="lineno"> 78</span> <span class="comment">// the palindrome on having center at opposite end,</span></div>
<div class="line"><span class="lineno"> 79</span> <span class="comment">// and the string between i and right end,</span></div>
<div class="line"><span class="lineno"> 80</span> <span class="comment">// considering &#39;bigger_center&#39; as center of palindrome</span></div>
<div class="line"><span class="lineno"> 81</span> palindrome_max_half_length[i] = <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/min.html">std::min</a>(</div>
<div class="line"><span class="lineno"> 82</span> palindrome_max_half_length[opposite_to_i], right - i);</div>
<div class="line"><span class="lineno"> 83</span> }</div>
<div class="line"><span class="lineno"> 84</span> </div>
<div class="line"><span class="lineno"> 85</span> <span class="comment">// expanding the palindrome across the maximum stored length in the</span></div>
<div class="line"><span class="lineno"> 86</span> <span class="comment">// array, centered at i</span></div>
<div class="line"><span class="lineno"> 87</span> <span class="keywordflow">while</span> (stuffed_string[i + (palindrome_max_half_length[i] + 1)] ==</div>
<div class="line"><span class="lineno"> 88</span> stuffed_string[i - (palindrome_max_half_length[i] + 1)]) {</div>
<div class="line"><span class="lineno"> 89</span> palindrome_max_half_length[i]++;</div>
<div class="line"><span class="lineno"> 90</span> }</div>
<div class="line"><span class="lineno"> 91</span> </div>
<div class="line"><span class="lineno"> 92</span> <span class="comment">// if palindrome centered at i exceeds the rightmost end of</span></div>
<div class="line"><span class="lineno"> 93</span> <span class="comment">// palindrome centered at &#39;bigger_center&#39;, then i will be made the</span></div>
<div class="line"><span class="lineno"> 94</span> <span class="comment">// &#39;bigger_center&#39; and right value will also be updated with respect</span></div>
<div class="line"><span class="lineno"> 95</span> <span class="comment">// to center i</span></div>
<div class="line"><span class="lineno"> 96</span> <span class="keywordflow">if</span> (i + palindrome_max_half_length[i] &gt; right) {</div>
<div class="line"><span class="lineno"> 97</span> bigger_center = i;</div>
<div class="line"><span class="lineno"> 98</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/left.html">right</a> = i + palindrome_max_half_length[i];</div>
<div class="line"><span class="lineno"> 99</span> }</div>
<div class="line"><span class="lineno"> 100</span> }</div>
<div class="line"><span class="lineno"> 101</span> </div>
<div class="line"><span class="lineno"> 102</span> <span class="comment">// now extracting the first largest palindrome</span></div>
<div class="line"><span class="lineno"> 103</span> uint64_t half_length = 0; <span class="comment">// half length of the largest palindrome</span></div>
<div class="line"><span class="lineno"> 104</span> uint64_t center_index = 0; <span class="comment">// index of center of the largest palindrome</span></div>
<div class="line"><span class="lineno"> 105</span> </div>
<div class="line"><span class="lineno"> 106</span> <span class="keywordflow">for</span> (uint64_t i = 1; i &lt; stuffed_string.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">size</a>() - 1; i++) {</div>
<div class="line"><span class="lineno"> 107</span> <span class="keywordflow">if</span> (palindrome_max_half_length[i] &gt; half_length) {</div>
<div class="line"><span class="lineno"> 108</span> half_length = palindrome_max_half_length[i];</div>
<div class="line"><span class="lineno"> 109</span> center_index = i;</div>
<div class="line"><span class="lineno"> 110</span> }</div>
<div class="line"><span class="lineno"> 111</span> }</div>
<div class="line"><span class="lineno"> 112</span> </div>
<div class="line"><span class="lineno"> 113</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> palindromic_substring =</div>
<div class="line"><span class="lineno"> 114</span> <span class="stringliteral">&quot;&quot;</span>; <span class="comment">// contains the resulting largest palindrome</span></div>
<div class="line"><span class="lineno"> 115</span> </div>
<div class="line"><span class="lineno"> 116</span> <span class="keywordflow">if</span> (half_length &gt; 0) {</div>
<div class="line"><span class="lineno"> 117</span> <span class="comment">// extra information: when &#39;#&#39; is the center, then palindromic</span></div>
<div class="line"><span class="lineno"> 118</span> <span class="comment">// substring will have even length, else palindromic substring will</span></div>
<div class="line"><span class="lineno"> 119</span> <span class="comment">// have odd length</span></div>
<div class="line"><span class="lineno"> 120</span> </div>
<div class="line"><span class="lineno"> 121</span> uint64_t start =</div>
<div class="line"><span class="lineno"> 122</span> center_index - half_length +</div>
<div class="line"><span class="lineno"> 123</span> 1; <span class="comment">// index of first character of palindromic substring</span></div>
<div class="line"><span class="lineno"> 124</span> uint64_t <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/iterator/end.html">end</a> =</div>
<div class="line"><span class="lineno"> 125</span> center_index + half_length -</div>
<div class="line"><span class="lineno"> 126</span> 1; <span class="comment">// index of last character of palindromic substring</span></div>
<div class="line"><span class="lineno"> 127</span> <span class="keywordflow">for</span> (uint64_t index = start; index &lt;= <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/iterator/end.html">end</a>; index += 2) {</div>
<div class="line"><span class="lineno"> 128</span> palindromic_substring += stuffed_string[index];</div>
<div class="line"><span class="lineno"> 129</span> }</div>
<div class="line"><span class="lineno"> 130</span> } <span class="keywordflow">else</span> {</div>
<div class="line"><span class="lineno"> 131</span> <span class="comment">// if length = 0, then there does not exist any palindrome of length</span></div>
<div class="line"><span class="lineno"> 132</span> <span class="comment">// &gt; 1 so we can assign any character of length 1 from string as the</span></div>
<div class="line"><span class="lineno"> 133</span> <span class="comment">// palindromic substring</span></div>
<div class="line"><span class="lineno"> 134</span> palindromic_substring = prototype[0];</div>
<div class="line"><span class="lineno"> 135</span> }</div>
<div class="line"><span class="lineno"> 136</span> <span class="keywordflow">return</span> palindromic_substring;</div>
<div class="line"><span class="lineno"> 137</span> </div>
<div class="line"><span class="lineno"> 138</span> } <span class="keywordflow">else</span> {</div>
<div class="line"><span class="lineno"> 139</span> <span class="comment">// handling case when string is empty</span></div>
<div class="line"><span class="lineno"> 140</span> <span class="keywordflow">return</span> <span class="stringliteral">&quot;&quot;</span>;</div>
<div class="line"><span class="lineno"> 141</span> }</div>
<div class="line"><span class="lineno"> 142</span>}</div>
<div class="ttc" id="abasic_string_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a></div></div>
<div class="ttc" id="aend_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/iterator/end.html">std::end</a></div><div class="ttdeci">T end(T... args)</div></div>
<div class="ttc" id="aleft_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/left.html">std::right</a></div><div class="ttdeci">T right(T... args)</div></div>
<div class="ttc" id="amin_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/algorithm/min.html">std::min</a></div><div class="ttdeci">T min(T... args)</div></div>
<div class="ttc" id="asize_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">std::string::size</a></div><div class="ttdeci">T size(T... args)</div></div>
<div class="ttc" id="avector_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a></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/d39/manacher__algorithm_8cpp_a95e6a2976bb2f332898f373941d52098_cgraph.svg" width="304" height="86"><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="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa8dca7b867074164d5f45b0f3851269d">&#9670;&#160;</a></span>test()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static void test </td>
<td>(</td>
<td class="paramname"><span class="paramname"><em></em></span></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>Self-test implementations. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 151</span> {</div>
<div class="line"><span class="lineno"> 152</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;&quot;</span>) == <span class="stringliteral">&quot;&quot;</span>);</div>
<div class="line"><span class="lineno"> 153</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;abababc&quot;</span>) == <span class="stringliteral">&quot;ababa&quot;</span>);</div>
<div class="line"><span class="lineno"> 154</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;cbaabd&quot;</span>) == <span class="stringliteral">&quot;baab&quot;</span>);</div>
<div class="line"><span class="lineno"> 155</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;DedzefDeD&quot;</span>) == <span class="stringliteral">&quot;DeD&quot;</span>);</div>
<div class="line"><span class="lineno"> 156</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;XZYYXXYZXX&quot;</span>) == <span class="stringliteral">&quot;YXXY&quot;</span>);</div>
<div class="line"><span class="lineno"> 157</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;1sm222m10abc&quot;</span>) == <span class="stringliteral">&quot;m222m&quot;</span>);</div>
<div class="line"><span class="lineno"> 158</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;798989591&quot;</span>) == <span class="stringliteral">&quot;98989&quot;</span>);</div>
<div class="line"><span class="lineno"> 159</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;xacdedcax&quot;</span>) == <span class="stringliteral">&quot;xacdedcax&quot;</span>);</div>
<div class="line"><span class="lineno"> 160</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;xaccax&quot;</span>) == <span class="stringliteral">&quot;xaccax&quot;</span>);</div>
<div class="line"><span class="lineno"> 161</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;a&quot;</span>) == <span class="stringliteral">&quot;a&quot;</span>);</div>
<div class="line"><span class="lineno"> 162</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;xy&quot;</span>) == <span class="stringliteral">&quot;x&quot;</span>);</div>
<div class="line"><span class="lineno"> 163</span> assert(strings::manacher::manacher(<span class="stringliteral">&quot;abced&quot;</span>) == <span class="stringliteral">&quot;a&quot;</span>);</div>
<div class="line"><span class="lineno"> 164</span> </div>
<div class="line"><span class="lineno"> 165</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;All tests have passed!&quot;</span> &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"> 166</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/d39/manacher__algorithm_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg" width="174" 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>
</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_73a3cc5065b223eb41b02873c0e19f0e.html">strings</a></li><li class="navelem"><a class="el" href="../../d3/d39/manacher__algorithm_8cpp.html">manacher_algorithm.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>
</ul>
</div>
</body>
</html>