|
|
|
|
@@ -1,3 +1,4 @@
|
|
|
|
|
<!-- HTML header for doxygen 1.12.0-->
|
|
|
|
|
<!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>
|
|
|
|
|
@@ -5,10 +6,15 @@
|
|
|
|
|
<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++: Trie Class Reference</title>
|
|
|
|
|
<title>TheAlgorithms/C++: Trie Class Reference</title>
|
|
|
|
|
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
|
|
|
|
|
<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="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
DoxygenAwesomeDarkModeToggle.init()
|
|
|
|
|
</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>
|
|
|
|
|
@@ -18,14 +24,24 @@
|
|
|
|
|
<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 type="text/javascript">
|
|
|
|
|
window.MathJax = {
|
|
|
|
|
options: {
|
|
|
|
|
ignoreHtmlClass: 'tex2jax_ignore',
|
|
|
|
|
processHtmlClass: 'tex2jax_process'
|
|
|
|
|
},
|
|
|
|
|
loader: {
|
|
|
|
|
load: ['[tex]/ams']
|
|
|
|
|
},
|
|
|
|
|
tex: {
|
|
|
|
|
macros: {},
|
|
|
|
|
packages: ['base','configmacros','ams']
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</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>
|
|
|
|
|
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
|
|
|
|
|
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
|
|
|
|
|
<link href="../../doxygen-awesome.css" rel="stylesheet" type="text/css"/>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
|
|
|
@@ -33,10 +49,11 @@ MathJax.Hub.Config({
|
|
|
|
|
<table cellspacing="0" cellpadding="0">
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr id="projectrow">
|
|
|
|
|
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
|
|
|
|
|
<td id="projectalign">
|
|
|
|
|
<div id="projectname">Algorithms_in_C++<span id="projectnumber"> 1.0.0</span>
|
|
|
|
|
<div id="projectname">TheAlgorithms/C++<span id="projectnumber"> 1.0.0</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="projectbrief">Set of algorithms implemented in C++.</div>
|
|
|
|
|
<div id="projectbrief">All the algorithms implemented in C++</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
@@ -131,37 +148,37 @@ Public Member Functions</h2></td></tr>
|
|
|
|
|
<tr class="memitem:a6af57e9f25d0d0a2d59eea5a4a802908" id="r_a6af57e9f25d0d0a2d59eea5a4a802908"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="#a6af57e9f25d0d0a2d59eea5a4a802908">Trie</a> ()</td></tr>
|
|
|
|
|
<tr class="memdesc:a6af57e9f25d0d0a2d59eea5a4a802908"><td class="mdescLeft"> </td><td class="mdescRight">constructor to initialise the root of the trie. <br /></td></tr>
|
|
|
|
|
<tr class="separator:a6af57e9f25d0d0a2d59eea5a4a802908"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
<tr class="memitem:afd8b79959009b554e98ea7128b2886f2" id="r_afd8b79959009b554e98ea7128b2886f2"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="#afd8b79959009b554e98ea7128b2886f2">insert</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> &word)</td></tr>
|
|
|
|
|
<tr class="memitem:afd8b79959009b554e98ea7128b2886f2" id="r_afd8b79959009b554e98ea7128b2886f2"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="#afd8b79959009b554e98ea7128b2886f2">insert</a> (const std::string &word)</td></tr>
|
|
|
|
|
<tr class="separator:afd8b79959009b554e98ea7128b2886f2"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
<tr class="memitem:a411e77126930a0942dd7b65e96b15206" id="r_a411e77126930a0942dd7b65e96b15206"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="#a411e77126930a0942dd7b65e96b15206">search</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> &word)</td></tr>
|
|
|
|
|
<tr class="memitem:a411e77126930a0942dd7b65e96b15206" id="r_a411e77126930a0942dd7b65e96b15206"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="#a411e77126930a0942dd7b65e96b15206">search</a> (const std::string &word)</td></tr>
|
|
|
|
|
<tr class="separator:a411e77126930a0942dd7b65e96b15206"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
<tr class="memitem:a734a08b52b8ad73bdd1f36ae8348056e" id="r_a734a08b52b8ad73bdd1f36ae8348056e"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="#a734a08b52b8ad73bdd1f36ae8348056e">removeWord</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> &word)</td></tr>
|
|
|
|
|
<tr class="memitem:a734a08b52b8ad73bdd1f36ae8348056e" id="r_a734a08b52b8ad73bdd1f36ae8348056e"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="#a734a08b52b8ad73bdd1f36ae8348056e">removeWord</a> (const std::string &word)</td></tr>
|
|
|
|
|
<tr class="separator:a734a08b52b8ad73bdd1f36ae8348056e"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
</table><table class="memberdecls">
|
|
|
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pri-methods" name="pri-methods"></a>
|
|
|
|
|
Private Member Functions</h2></td></tr>
|
|
|
|
|
<tr class="memitem:a26941759ecf94d67a27d4a610bc0f63d" id="r_a26941759ecf94d67a27d4a610bc0f63d"><td class="memItemLeft" align="right" valign="top"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/memory/shared_ptr.html">std::shared_ptr</a>< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> > </td><td class="memItemRight" valign="bottom"><a class="el" href="#a26941759ecf94d67a27d4a610bc0f63d">removeWordHelper</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> &word, <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/memory/shared_ptr.html">std::shared_ptr</a>< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> > curr, size_t index)</td></tr>
|
|
|
|
|
<tr class="memitem:a26941759ecf94d67a27d4a610bc0f63d" id="r_a26941759ecf94d67a27d4a610bc0f63d"><td class="memItemLeft" align="right" valign="top">std::shared_ptr< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> > </td><td class="memItemRight" valign="bottom"><a class="el" href="#a26941759ecf94d67a27d4a610bc0f63d">removeWordHelper</a> (const std::string &word, std::shared_ptr< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> > curr, size_t index)</td></tr>
|
|
|
|
|
<tr class="separator:a26941759ecf94d67a27d4a610bc0f63d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
</table><table class="memberdecls">
|
|
|
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pri-static-methods" name="pri-static-methods"></a>
|
|
|
|
|
Static Private Member Functions</h2></td></tr>
|
|
|
|
|
<tr class="memitem:a6d10eb1669453395d1900ebd401954fb" id="r_a6d10eb1669453395d1900ebd401954fb"><td class="memItemLeft" align="right" valign="top">static bool </td><td class="memItemRight" valign="bottom"><a class="el" href="#a6d10eb1669453395d1900ebd401954fb">hasChildren</a> (<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/memory/shared_ptr.html">std::shared_ptr</a>< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> > <a class="el" href="../../d5/da1/structnode.html">node</a>)</td></tr>
|
|
|
|
|
<tr class="memitem:a6d10eb1669453395d1900ebd401954fb" id="r_a6d10eb1669453395d1900ebd401954fb"><td class="memItemLeft" align="right" valign="top">static bool </td><td class="memItemRight" valign="bottom"><a class="el" href="#a6d10eb1669453395d1900ebd401954fb">hasChildren</a> (std::shared_ptr< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> > <a class="el" href="../../d5/da1/structnode.html">node</a>)</td></tr>
|
|
|
|
|
<tr class="separator:a6d10eb1669453395d1900ebd401954fb"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
</table><table class="memberdecls">
|
|
|
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pri-attribs" name="pri-attribs"></a>
|
|
|
|
|
Private Attributes</h2></td></tr>
|
|
|
|
|
<tr class="memitem:a58b359fad33ca0064bd75a0d41a7b66d" id="r_a58b359fad33ca0064bd75a0d41a7b66d"><td class="memItemLeft" align="right" valign="top"><a id="a58b359fad33ca0064bd75a0d41a7b66d" name="a58b359fad33ca0064bd75a0d41a7b66d"></a>
|
|
|
|
|
<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/memory/shared_ptr.html">std::shared_ptr</a>< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> > </td><td class="memItemRight" valign="bottom"><b>m_root</b></td></tr>
|
|
|
|
|
<tr class="memitem:a58b359fad33ca0064bd75a0d41a7b66d" id="r_a58b359fad33ca0064bd75a0d41a7b66d"><td class="memItemLeft" align="right" valign="top">std::shared_ptr< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> > </td><td class="memItemRight" valign="bottom"><a class="el" href="#a58b359fad33ca0064bd75a0d41a7b66d">m_root</a></td></tr>
|
|
|
|
|
<tr class="separator:a58b359fad33ca0064bd75a0d41a7b66d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
</table><table class="memberdecls">
|
|
|
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pri-static-attribs" name="pri-static-attribs"></a>
|
|
|
|
|
Static Private Attributes</h2></td></tr>
|
|
|
|
|
<tr class="memitem:a7c3ba4caf24378826a789848629177bd" id="r_a7c3ba4caf24378826a789848629177bd"><td class="memItemLeft" align="right" valign="top"><a id="a7c3ba4caf24378826a789848629177bd" name="a7c3ba4caf24378826a789848629177bd"></a>
|
|
|
|
|
static constexpr size_t </td><td class="memItemRight" valign="bottom"><b>ALPHABETS</b> = 26</td></tr>
|
|
|
|
|
<tr class="memitem:a7c3ba4caf24378826a789848629177bd" id="r_a7c3ba4caf24378826a789848629177bd"><td class="memItemLeft" align="right" valign="top">static constexpr size_t </td><td class="memItemRight" valign="bottom"><a class="el" href="#a7c3ba4caf24378826a789848629177bd">ALPHABETS</a> = 26</td></tr>
|
|
|
|
|
<tr class="separator:a7c3ba4caf24378826a789848629177bd"><td class="memSeparator" colspan="2"> </td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
|
|
|
<div class="textblock"><p>A basic implementation of trie class to store only lower-case strings. You can extend the implementation to all the ASCII characters by changing the value of @ ALPHABETS to 128. </p>
|
|
|
|
|
|
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html#l00016">16</a> of file <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html">trie_modern.cpp</a>.</p>
|
|
|
|
|
</div><h2 class="groupheader">Constructor & Destructor Documentation</h2>
|
|
|
|
|
<a id="a6af57e9f25d0d0a2d59eea5a4a802908" name="a6af57e9f25d0d0a2d59eea5a4a802908"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a6af57e9f25d0d0a2d59eea5a4a802908">◆ </a></span>Trie()</h2>
|
|
|
|
|
@@ -187,8 +204,9 @@ static constexpr size_t </td><td class="memItemRight" valign="bottom"><b>AL
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
|
|
|
|
|
<p>constructor to initialise the root of the trie. </p>
|
|
|
|
|
<div class="fragment"><div class="line"><span class="lineno"> 103</span>: m_root(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared.html">std::make_shared<TrieNode></a>()) {}</div>
|
|
|
|
|
<div class="ttc" id="amake_shared_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared.html">std::make_shared</a></div><div class="ttdeci">T make_shared(T... args)</div></div>
|
|
|
|
|
|
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html#l00103">103</a> of file <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html">trie_modern.cpp</a>.</p>
|
|
|
|
|
<div class="fragment"><div class="line"><span class="lineno"> 103</span>: m_root(std::make_shared<TrieNode>()) {}</div>
|
|
|
|
|
</div><!-- fragment -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
@@ -205,7 +223,7 @@ static constexpr size_t </td><td class="memItemRight" valign="bottom"><b>AL
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">static bool Trie::hasChildren </td>
|
|
|
|
|
<td>(</td>
|
|
|
|
|
<td class="paramtype"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/memory/shared_ptr.html">std::shared_ptr</a>< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> ></td> <td class="paramname"><span class="paramname"><em>node</em></span></td><td>)</td>
|
|
|
|
|
<td class="paramtype">std::shared_ptr< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> ></td> <td class="paramname"><span class="paramname"><em>node</em></span></td><td>)</td>
|
|
|
|
|
<td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
@@ -224,6 +242,8 @@ static constexpr size_t </td><td class="memItemRight" valign="bottom"><b>AL
|
|
|
|
|
<dl class="section return"><dt>Returns</dt><dd><code>true</code> if a child is found </dd>
|
|
|
|
|
<dd>
|
|
|
|
|
<code>false</code> if a child is not found </dd></dl>
|
|
|
|
|
|
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html#l00041">41</a> of file <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html">trie_modern.cpp</a>.</p>
|
|
|
|
|
<div class="fragment"><div class="line"><span class="lineno"> 41</span> {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 42</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < ALPHABETS; i++) {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 43</span> <span class="keywordflow">if</span> (<a class="code hl_class" href="../../d5/da1/structnode.html">node</a>->character[i]) {</div>
|
|
|
|
|
@@ -232,7 +252,7 @@ static constexpr size_t </td><td class="memItemRight" valign="bottom"><b>AL
|
|
|
|
|
<div class="line"><span class="lineno"> 46</span> }</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 47</span> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 48</span> }</div>
|
|
|
|
|
<div class="ttc" id="astructnode_html"><div class="ttname"><a href="../../d5/da1/structnode.html">node</a></div><div class="ttdef"><b>Definition</b> binary_search_tree.cpp:11</div></div>
|
|
|
|
|
<div class="ttc" id="astructnode_html"><div class="ttname"><a href="../../d5/da1/structnode.html">node</a></div><div class="ttdef"><b>Definition</b> <a href="../../d3/d26/binary__search__tree_8cpp_source.html#l00011">binary_search_tree.cpp:11</a></div></div>
|
|
|
|
|
</div><!-- fragment -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
@@ -248,7 +268,7 @@ static constexpr size_t </td><td class="memItemRight" valign="bottom"><b>AL
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">void Trie::insert </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> &</td> <td class="paramname"><span class="paramname"><em>word</em></span></td><td>)</td>
|
|
|
|
|
<td class="paramtype">const std::string &</td> <td class="paramname"><span class="paramname"><em>word</em></span></td><td>)</td>
|
|
|
|
|
<td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
@@ -264,6 +284,8 @@ static constexpr size_t </td><td class="memItemRight" valign="bottom"><b>AL
|
|
|
|
|
</table>
|
|
|
|
|
</dd>
|
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html#l00109">109</a> of file <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html">trie_modern.cpp</a>.</p>
|
|
|
|
|
<div class="fragment"><div class="line"><span class="lineno"> 109</span> {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 110</span> <span class="keyword">auto</span> curr = m_root;</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 111</span> <span class="keywordflow">for</span> (<span class="keywordtype">char</span> ch : word) {</div>
|
|
|
|
|
@@ -272,19 +294,14 @@ static constexpr size_t </td><td class="memItemRight" valign="bottom"><b>AL
|
|
|
|
|
<div class="line"><span class="lineno"> 114</span> <span class="comment">// if a node for current word is not already present in trie, create</span></div>
|
|
|
|
|
<div class="line"><span class="lineno"> 115</span> <span class="comment">// a new node for it.</span></div>
|
|
|
|
|
<div class="line"><span class="lineno"> 116</span> <span class="keywordflow">if</span> (!curr->character[index]) {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 117</span> curr->character[index] = <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared.html">std::make_shared<TrieNode></a>();</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 117</span> curr->character[index] = std::make_shared<TrieNode>();</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 118</span> }</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 119</span> </div>
|
|
|
|
|
<div class="line"><span class="lineno"> 120</span> curr = curr->character[index];</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 121</span> }</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 122</span> curr->isEndOfWord = <span class="keyword">true</span>;</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 123</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="../../dd/d2f/class_trie_afd8b79959009b554e98ea7128b2886f2_cgraph.svg" width="268" 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><!-- fragment -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<a id="a734a08b52b8ad73bdd1f36ae8348056e" name="a734a08b52b8ad73bdd1f36ae8348056e"></a>
|
|
|
|
|
@@ -299,7 +316,7 @@ Here is the call graph for this function:</div>
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">void Trie::removeWord </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> &</td> <td class="paramname"><span class="paramname"><em>word</em></span></td><td>)</td>
|
|
|
|
|
<td class="paramtype">const std::string &</td> <td class="paramname"><span class="paramname"><em>word</em></span></td><td>)</td>
|
|
|
|
|
<td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
@@ -309,10 +326,12 @@ Here is the call graph for this function:</div>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
|
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html#l00148">148</a> of file <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html">trie_modern.cpp</a>.</p>
|
|
|
|
|
<div class="fragment"><div class="line"><span class="lineno"> 148</span> {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 149</span> m_root = <a class="code hl_function" href="#a26941759ecf94d67a27d4a610bc0f63d">removeWordHelper</a>(word, m_root, 0);</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 150</span> }</div>
|
|
|
|
|
<div class="ttc" id="aclass_trie_html_a26941759ecf94d67a27d4a610bc0f63d"><div class="ttname"><a href="#a26941759ecf94d67a27d4a610bc0f63d">Trie::removeWordHelper</a></div><div class="ttdeci">std::shared_ptr< TrieNode > removeWordHelper(const std::string &word, std::shared_ptr< TrieNode > curr, size_t index)</div><div class="ttdef"><b>Definition</b> trie_modern.cpp:64</div></div>
|
|
|
|
|
<div class="ttc" id="aclass_trie_html_a26941759ecf94d67a27d4a610bc0f63d"><div class="ttname"><a href="#a26941759ecf94d67a27d4a610bc0f63d">Trie::removeWordHelper</a></div><div class="ttdeci">std::shared_ptr< TrieNode > removeWordHelper(const std::string &word, std::shared_ptr< TrieNode > curr, size_t index)</div><div class="ttdef"><b>Definition</b> <a href="../../dc/d93/trie__modern_8cpp_source.html#l00064">trie_modern.cpp:64</a></div></div>
|
|
|
|
|
</div><!-- fragment -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
@@ -326,14 +345,14 @@ Here is the call graph for this function:</div>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/memory/shared_ptr.html">std::shared_ptr</a>< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> > Trie::removeWordHelper </td>
|
|
|
|
|
<td class="memname">std::shared_ptr< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> > Trie::removeWordHelper </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> &</td> <td class="paramname"><span class="paramname"><em>word</em></span>, </td>
|
|
|
|
|
<td class="paramtype">const std::string &</td> <td class="paramname"><span class="paramname"><em>word</em></span>, </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="paramkey"></td>
|
|
|
|
|
<td></td>
|
|
|
|
|
<td class="paramtype"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/memory/shared_ptr.html">std::shared_ptr</a>< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> ></td> <td class="paramname"><span class="paramname"><em>curr</em></span>, </td>
|
|
|
|
|
<td class="paramtype">std::shared_ptr< <a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a> ></td> <td class="paramname"><span class="paramname"><em>curr</em></span>, </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="paramkey"></td>
|
|
|
|
|
@@ -362,8 +381,10 @@ Here is the call graph for this function:</div>
|
|
|
|
|
</table>
|
|
|
|
|
</dd>
|
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html#l00064">64</a> of file <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html">trie_modern.cpp</a>.</p>
|
|
|
|
|
<div class="fragment"><div class="line"><span class="lineno"> 66</span> {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 67</span> <span class="keywordflow">if</span> (word.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">size</a>() == index) {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 67</span> <span class="keywordflow">if</span> (word.size() == index) {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 68</span> <span class="keywordflow">if</span> (curr->isEndOfWord) {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 69</span> curr->isEndOfWord = <span class="keyword">false</span>;</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 70</span> }</div>
|
|
|
|
|
@@ -378,7 +399,7 @@ Here is the call graph for this function:</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 79</span> <span class="comment">// Throw a runtime error in case the user enters a word which is not</span></div>
|
|
|
|
|
<div class="line"><span class="lineno"> 80</span> <span class="comment">// present in the trie.</span></div>
|
|
|
|
|
<div class="line"><span class="lineno"> 81</span> <span class="keywordflow">if</span> (!curr->character[idx]) {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 82</span> <span class="keywordflow">throw</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/error/runtime_error.html">std::runtime_error</a>(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/utility/move.html">std::move</a>(<a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a>(<span class="stringliteral">"Word not found."</span>)));</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 82</span> <span class="keywordflow">throw</span> std::runtime_error(std::move(std::string(<span class="stringliteral">"Word not found."</span>)));</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> curr->character[idx] =</div>
|
|
|
|
|
@@ -396,17 +417,8 @@ Here is the call graph for this function:</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 97</span> }</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 98</span> <span class="keywordflow">return</span> <span class="keyword">nullptr</span>;</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 99</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="aclass_trie_html_a6d10eb1669453395d1900ebd401954fb"><div class="ttname"><a href="#a6d10eb1669453395d1900ebd401954fb">Trie::hasChildren</a></div><div class="ttdeci">static bool hasChildren(std::shared_ptr< TrieNode > node)</div><div class="ttdef"><b>Definition</b> trie_modern.cpp:41</div></div>
|
|
|
|
|
<div class="ttc" id="amove_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/utility/move.html">std::move</a></div><div class="ttdeci">T move(T... args)</div></div>
|
|
|
|
|
<div class="ttc" id="aruntime_error_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/error/runtime_error.html">std::runtime_error</a></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><!-- 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="../../dd/d2f/class_trie_a26941759ecf94d67a27d4a610bc0f63d_cgraph.svg" width="342" height="135"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="ttc" id="aclass_trie_html_a6d10eb1669453395d1900ebd401954fb"><div class="ttname"><a href="#a6d10eb1669453395d1900ebd401954fb">Trie::hasChildren</a></div><div class="ttdeci">static bool hasChildren(std::shared_ptr< TrieNode > node)</div><div class="ttdef"><b>Definition</b> <a href="../../dc/d93/trie__modern_8cpp_source.html#l00041">trie_modern.cpp:41</a></div></div>
|
|
|
|
|
</div><!-- fragment -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<a id="a411e77126930a0942dd7b65e96b15206" name="a411e77126930a0942dd7b65e96b15206"></a>
|
|
|
|
|
@@ -421,7 +433,7 @@ Here is the call graph for this function:</div>
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">bool Trie::search </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> &</td> <td class="paramname"><span class="paramname"><em>word</em></span></td><td>)</td>
|
|
|
|
|
<td class="paramtype">const std::string &</td> <td class="paramname"><span class="paramname"><em>word</em></span></td><td>)</td>
|
|
|
|
|
<td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
@@ -440,6 +452,8 @@ Here is the call graph for this function:</div>
|
|
|
|
|
<dl class="section return"><dt>Returns</dt><dd>True if the word is found in trie and isEndOfWord is set to true. </dd>
|
|
|
|
|
<dd>
|
|
|
|
|
False if word is not found in trie or isEndOfWord is set to false. </dd></dl>
|
|
|
|
|
|
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html#l00132">132</a> of file <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html">trie_modern.cpp</a>.</p>
|
|
|
|
|
<div class="fragment"><div class="line"><span class="lineno"> 132</span> {</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 133</span> <span class="keyword">auto</span> curr = m_root;</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 134</span> <span class="keywordflow">for</span> (<span class="keywordtype">char</span> ch : word) {</div>
|
|
|
|
|
@@ -455,10 +469,59 @@ False if word is not found in trie or isEndOfWord is set to false. </dd></dl>
|
|
|
|
|
<div class="line"><span class="lineno"> 144</span> <span class="keywordflow">return</span> curr->isEndOfWord;</div>
|
|
|
|
|
<div class="line"><span class="lineno"> 145</span> }</div>
|
|
|
|
|
</div><!-- fragment -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<h2 class="groupheader">Member Data Documentation</h2>
|
|
|
|
|
<a id="a7c3ba4caf24378826a789848629177bd" name="a7c3ba4caf24378826a789848629177bd"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a7c3ba4caf24378826a789848629177bd">◆ </a></span>ALPHABETS</h2>
|
|
|
|
|
|
|
|
|
|
<div class="memitem">
|
|
|
|
|
<div class="memproto">
|
|
|
|
|
<table class="mlabels">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">size_t Trie::ALPHABETS = 26</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="mlabels-right">
|
|
|
|
|
<span class="mlabels"><span class="mlabel">static</span><span class="mlabel">constexpr</span><span class="mlabel">private</span></span> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
|
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html#l00018">18</a> of file <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html">trie_modern.cpp</a>.</p>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<a id="a58b359fad33ca0064bd75a0d41a7b66d" name="a58b359fad33ca0064bd75a0d41a7b66d"></a>
|
|
|
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a58b359fad33ca0064bd75a0d41a7b66d">◆ </a></span>m_root</h2>
|
|
|
|
|
|
|
|
|
|
<div class="memitem">
|
|
|
|
|
<div class="memproto">
|
|
|
|
|
<table class="mlabels">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="mlabels-left">
|
|
|
|
|
<table class="memname">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="memname">std::shared_ptr<<a class="el" href="../../de/d48/struct_trie_1_1_trie_node.html">TrieNode</a>> Trie::m_root</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="mlabels-right">
|
|
|
|
|
<span class="mlabels"><span class="mlabel">private</span></span> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div><div class="memdoc">
|
|
|
|
|
|
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html#l00154">154</a> of file <a class="el" href="../../dc/d93/trie__modern_8cpp_source.html">trie_modern.cpp</a>.</p>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<hr/>The documentation for this class was generated from the following file:<ul>
|
|
|
|
|
<li>data_structures/<a class="el" href="../../dc/d93/trie__modern_8cpp.html">trie_modern.cpp</a></li>
|
|
|
|
|
<li>data_structures/<a class="el" href="../../dc/d93/trie__modern_8cpp_source.html">trie_modern.cpp</a></li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div><!-- contents -->
|
|
|
|
|
</div><!-- doc-content -->
|
|
|
|
|
|