<@U5UU34LPK> <@U10EJRH2L> the purpose of the trie ...
# announcements
l
@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
List<AppModel>
(AppModel store all necessary info of an Android app). Here's the
getLeaves
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 ->
            child.value.getLeaves()
        }
    }
}
Is there a better way to do this? The part where it return listOf(value) seems bad to me.
k
Why are those things in a trie exactly?
r
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.
k
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.
1
Now that I think about it they're probably not useful at all with a
Node
class, they're meant for file storage or more "bare metal" languages.
l
@karelpeeters the key is for trie traversal, the value is to return the AppModel.
when searching for a certain app, it uses the
key
to traverse, which I assume should be fairly fast since it won't be dealing with
value
.
k
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
k
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 🙂.
l
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
k
contains
is probably better indeed, you might even want to look into string metrics: https://en.wikipedia.org/wiki/String_metric.