Searching a list is O(n), whereas a set lookup is O(1).
e
ephemient
07/13/2023, 7:03 PM
on the other hand, a set takes a bit more memory and may take significantly more time to construct, especially if you have very deep structures of `data class`es and other containers (as
hashCode()
isn't by default (and can't generally be) cached)
ephemient
07/13/2023, 7:04 PM
if you already have a list, and you are only checking one element for membership once, then there is zero purpose to converting the list to a set first
ephemient
07/13/2023, 7:05 PM
if any of those preconditions change, then a set may be a better idea
c
Colton Idle
07/13/2023, 7:31 PM
Cool. That's roughly where my mind was at as well, but wanted a sanity check