Replacing
encountered := map[uint64]bool{}
encountered := make(map[uint64]bool, len(elements))
Golang Hashmaps initially have one bucket with a size of 8. If more elements are added new buckets are created.
So giving a hint to initialize a correct number of things should always be faster.
Replacing
with Should be faster.Golang Hashmaps initially have one bucket with a size of 8. If more elements are added new buckets are created.
So giving a hint to initialize a correct number of things should always be faster.