Hacker News new | past | comments | ask | show | jobs | submit login

i saw the custom hashtable, but why was Map slow?



I believe it is because he did not pre allocate the map, so as it grew, it reallocated multiple times. Just a guess.


I 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


The 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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: