With the container / list package, you write your own loop for finding things. The reason this is not provided in the package is probably because Dystroy, who will hide the O (n) operation, said.
You cannot add a method, so you are just writing a loop.
for e := l.Front(); e != nil; e = e.Next() { data := e.Value.(dataType) // type assertion if /* test on data */ { // do something break } }
This is simple enough and the complexity of O (n) is obvious.
In the overview of data structures that come with Go that support search, don't miss the sort package. The functions there allow you to sort the slice in O (n log (n)), and then binary search in O (log (n)) time.
Finally, as Daniel suggested, consider third-party packages. There are several popular and mature packages for container types.
Sonia
source share