lab
08/16/2017, 9:18 PMList<AppModel>
(AppModel store all necessary info of an Android app). Here's the getLeaves
method that I'm testing around with:
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.karelpeeters
08/16/2017, 9:21 PMRuckus
08/16/2017, 9:22 PMkarelpeeters
08/16/2017, 9:22 PMNode
class, they're meant for file storage or more "bare metal" languages.lab
08/16/2017, 9:25 PMkey
to traverse, which I assume should be fairly fast since it won't be dealing with value
.karelpeeters
08/16/2017, 9:28 PMval apps: List<App>
, and then I'd do val results = apps.filter { it.name.startsWith(query) }
.lab
08/16/2017, 9:29 PMkarelpeeters
08/16/2017, 9:30 PMlab
08/16/2017, 9:31 PMkarelpeeters
08/16/2017, 9:31 PMcontains
is probably better indeed, you might even want to look into string metrics: https://en.wikipedia.org/wiki/String_metric.