3 ms·
I believe it is because he did not pre allocate the map, so as it grew, it reallocated multiple times. Just a guess.
by sethammons 3y ago
I believe it is because he did not pre allocate the map, so as it grew, it reallocated multiple times. Just a guess.
- tonymet 3y agoI double checked and he mentioned a couple other points. One was incrementally hashing the keys to reduce double read. The other was about storing pointers for the value structs more efficiently. I encourage implementing maps and other DS btw, i was just curious
- canucker2016 3y agoThe authour has already converted the code to using a pointer to value struct for storing in the standard go hash table in Solution 2. Solution 7 contains the code and description for the custom hash table. I can see where interleaving/inlining the hash generation of the station name/key with the search for the separator reduces the number of scans of bytes from 2-3x to just 1x. The second point in Solution 7 was the use of the byte slice to the underlying buffer when the station name is found in the buffer instead of creating a new string. This saves a memory allocation.