https://kotlinlang.org logo
Title
a

Andrew Gazelka

12/11/2018, 3:28 PM
is there a good equivalent of a "multiset" in Kotlin? I don't care about order. I simply care about element count and I want to compare equality between to multisets.
i.e.,
[1,4,4,7] == [7,4,1,4]
t

Tsvetozar Bonev

12/11/2018, 3:32 PM
You could easily implement this with a extension function
s

Shawn

12/11/2018, 3:32 PM
I don’t believe this is available in the stdlib
a

Andrew Gazelka

12/11/2018, 3:32 PM
alright, I'll just implement my own then
wait... I could probably just compare groupings
👆 1
a

Alan Evans

12/11/2018, 3:57 PM
What language does
multiset
come from? How does it differ from a
set
?
setOf(1, 4, 4, 7) == setOf(7, 4, 1, 4)
s

Shawn

12/11/2018, 3:59 PM
@Alan Evans I’ve seen it in C++, Google provides it for the JVM with Guava
it differs by allowing multiple instances of the same element
a

Alan Evans

12/11/2018, 4:00 PM
right, so
multiSetOf(1, 4, 4, 7) != multiSetOf(7, 4, 1, 1)
?
s

Shawn

12/11/2018, 4:00 PM
right