To stay on the same topice (almost :stuck_out_tong...
# getting-started
c
To stay on the same topice (almost šŸ˜› ), I have a question about data types. For each item, I have a KEY, a PATH and a NAME value. I would like to be able to find the two others quickly if I have any of the three. Is there a kotlin way to do it efficiently? I was thinking of doing a hashmap with a data class that contains the two other value, but then it only works if I searrch by KEY, not by PATH or NAME. Any idea?
h
you could create a ā€œtripleā€ hype
that has the vals first, second, and third
c
But can I search in a triple? Like if I know the second value, can I then easily get first and third?
a
how big is the collection? if it’s a few thousand items, you could probably do a linear search and it would still be quick also, how often do you expect to add/remove items from that collection and how often do you expect to query it?
h
create a custom type that extends iterable
c
It's a very tiny collection, and I do not plan to modify it at all. I was trying to mimic some kind of static searchable collection.
Thanks Hamza, I will try to create my custom type, it will be a good learning experience
k
create type, that have 3 maps inside?
a
if it’s tiny, the overhead of the hashmap could be greater than the benefit from better time complexity of the lookup
k
as long as each K/P/N are unique.
If you have 2 items with same name, but different path... what should it return?
c
They are. I am probably just going to create a custom iterable with a triple.
h
what you could possibly do is just have a type that holds three values, and hhave a list of them
then use map and filter
c
@Konstantin Petrukhnov They are unique šŸ™‚
@Hamza Good idea. I am discovering Kotlin, so thanks for all the advices šŸ™‚
h
np
c
@arekolek Thanks for the reminder of the HashMap overhead! I'll keep that in mind when dealing with small datasets.
a
Sure šŸ™‚ on the other hand I don’t care about that overhead if it’s convenient to use a map instead of using
list.find { }
. If the speed matters, you’ll probably notice it, no need to optimize prematurely
k
@arekolek what is tiny? At what size it get significantly better/worse?
c
Yes I tend to be guilty of that šŸ˜„
a
@Konstantin Petrukhnov that’s something one would have to measure
k
are we talking about 10s or 1000s?
h
im thinkimg 100-500
a
here’s an example in .NET, with add/remove

https://i.stack.imgur.com/O4ly9.pngā–¾

But I’d treat it more as a tidbit, than something that should guide development šŸ˜›