<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="164454" data-post-id="164454">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Nice project <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"> I am fond of algorithmic code, and really like to delve into these sort of projects.</p>
<p>I have a suggestion based on similar work I did for one of my projects: I maintain an open source <a href="https://github.com/lucaong/minisearch" rel="noopener nofollow ugc">client-side full text search engine</a> (JavaScript, not Elixir), that uses a radix tree (similar enough to a trie) under the hood as the index data structure.</p>
<p>I like to keep the API of the data structure very generic, and compose use-case specific code on top of it. In this case, what you could do, is implement the trie to basically expose the same API as a <code>Map</code> (limited to string keys), plus a few functions to expose the prefix search features. You already implement the <code>Access</code> behavior, so you’re on a good track with it.</p>
<p>The prefix search function could then return another trie (the sub-trie at that prefix) instead of a list of words. If the trie implements the <code>Enumerable</code> protocol, it would be easy enough to turn it into a list of entries.</p>
<p>The advantage would be that your Trie could be used for any use-case where it is a good match. Essentially, any case in which one needs a map of strings to values with efficient prefix search.</p>
<p>In my project, where I essentially apply what I just wrote, the basic data structure code is documented <a href="https://lucaong.github.io/minisearch/class/src/SearchableMap/SearchableMap.js~SearchableMap.html" rel="noopener nofollow ugc">here</a>. It’s JS, but it illustrates my point above.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="164454" data-batch-url="/posts/batch_likers">
                        5
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/call-for-criticism-a-minimal-trie-library/29355/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-164454" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="164454"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="164662" data-post-id="164662">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dimitarvp" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/120/38664_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dimitarvp
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="lucaong" data-post="12" data-topic="29355">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/48/21794_2.png" class="avatar"> lucaong:</div>
<blockquote>
<p>Nice project <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"> I am fond of algorithmic code, and really like to delve into these sort of projects.</p>
</blockquote>
</aside>
<p>Thank you! I think it’s pretty small and humble, you flatter me too much. <img src="https://forum.elixirforum.com/images/emoji/apple/blush.png?v=15" title=":blush:" class="emoji" alt=":blush:" loading="lazy" width="20" height="20"></p>
<p>Interesting feedback. I can see the value in having more user-oriented API being in another module. But I am 50/50 torn on it due to the project being very small at the moment. Would you still do it even with it being ~400 lines of code (minus the tests)? Perhaps it’s worth it to do some function renames so those that only return sub-tries – or in general don’t return strings – are apparent, while those that are meant for consumption (like <code>search</code>) are given a special small section in the docs to point at them? Hm. Not sure.</p>
<p>Furthermore, I have API that returns sub-tries – the <code>Access</code>-enabling functions. The <code>search</code> function internally uses <code>get</code> which returns a sub-trie as well (and then proceeds to extract all textual matches from it). Or you have something else in mind, on top of these?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="164662" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/call-for-criticism-a-minimal-trie-library/29355/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-164662" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="164662"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="164724" data-post-id="164724">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="dimitarvp" data-post="13" data-topic="29355">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/48/38664_2.png" class="avatar"> dimitarvp:</div>
<blockquote>
<p>I think it’s pretty small and humble, you flatter me too much. <img src="https://forum.elixirforum.com/images/emoji/apple/blush.png?v=15" title=":blush:" class="emoji" alt=":blush:" loading="lazy" width="20" height="20"></p>
</blockquote>
</aside>
<p>Someone once told me: the best compliment you can receive for your library is “this is too small” <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="dimitarvp" data-post="13" data-topic="29355">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/48/38664_2.png" class="avatar"> dimitarvp:</div>
<blockquote>
<p>Would you still do it even with it being ~400 lines of code (minus the tests)?</p>
</blockquote>
</aside>
<p>I think I would have one small module implementing the <code>Trie</code> with a <code>Map</code>-like interface, and the <code>Access</code> behavior and <code>Enumerable</code> protocol for it. Then, another module wrapping it and exposing the prefix search feature (or the other user-facing features). This way, each module might even get smaller or at least simpler. This is more or less what I did for the <a href="https://github.com/lucaong/cubdb/blob/master/lib/cubdb/btree.ex" rel="noopener nofollow ugc">B+tree implementation</a> internally powering <a href="https://github.com/lucaong/cubdb" rel="noopener nofollow ugc">cubdb</a>.</p>
<p>That said, this is my personal preference, but you’re the master of your library, you choose the goals, and you should do what you think is best <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>I am saying that because open-source is great, but it can also be lots of under-appreciated work, so I learned that one should always nurture and protect the part of their project that gives them pleasure and motivation. Often times, that means keeping autonomy, and while hearing feedback, ultimately do what <em>you</em> think is best, given your goals.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="164724" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/call-for-criticism-a-minimal-trie-library/29355/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-164724" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="164724"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>