3 ms·
The same would be true for the initial map: Replacing encountered := map[uint64]bool{} with encountered := make(map[uint64]bool, len(elements)) Should
by LordHeini 3y ago
The same would be true for the initial map:
Replacing
encountered := map[uint64]bool{}
with
encountered := make(map[uint64]bool, len(elements))
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.