<@U5UU34LPK> <@U10EJRH2L> the purpose of the trie ...
# announcements
@karelpeeters @Ruckus the purpose of the trie was for indexing and searching apps in an Android launcher. (The repo is at https://github.com/louisgv/janusLauncher) I'm refactoring the trie to return a
(AppModel store all necessary info of an Android app). Here's the
method that I'm testing around with:
Copy code
class WakeTrieNode (val key: Char?,
                    val value: AppModel?,
                    var isLeaf: Boolean,
                    val children: MutableMap<Char, WakeTrieNode> = mutableMapOf()) {

    fun getLeaves(): List<AppModel>{
        return if (isLeaf && value != null) listOf(value)
        else children.flatMap { child ->
Is there a better way to do this? The part where it return listOf(value) seems bad to me.
Why are those things in a trie exactly?
You're potentially creating an merging many lists. You may want to benchmark your results to see, but it may be more performant to pass in a mutable list and just append to it.
They're mostly used to store text more compactly, but you're undoing that by having a bunch of maybe not null fields per node.
Now that I think about it they're probably not useful at all with a
class, they're meant for file storage or more "bare metal" languages.
@karelpeeters the key is for trie traversal, the value is to return the AppModel.
when searching for a certain app, it uses the
to traverse, which I assume should be fairly fast since it won't be dealing with
I'd just have a
val apps: List<App>
, and then I'd do
val results = apps.filter { it.name.startsWith(query) }
I think this will perform way better then the trie one.
instead of startsWith I'm using contain
And if you want to improve reaction time while typing you can filter the previous list. And you can even keep a Stack of semi-filtered lists. I'll stop, I'm getting too exited 🙂.
performance wise it's pretty good, tho some friends of mine suggest making a trie and see if it could get better
@karelpeeters oh that's an awesome idea
is probably better indeed, you might even want to look into string metrics: https://en.wikipedia.org/wiki/String_metric.