3 ms·
> In that case, the ordering of the hash table on iteration can change. Order-dependent iteration of a hash table's items isn't exactly a central use case of t
by wutbrodo 8y ago
> In that case, the ordering of the hash table on iteration can change.
Order-dependent iteration of a hash table's items isn't exactly a central use case of the data structure and often isn't even guaranteed. I don't think that this example is really sufficient to suggest that hashing pointers is a bad idea (though it may be for other reasons).
- TrinaryWorksToo 8y agoIn golang it is purposefully randomized on every execution to prevent you from relying on iteration order
- delhanty 8y agoThat's actually better than the situation in C. In C, debug `malloc` may very well behave the same run after run. Then you move into production, and release `malloc` behaves differently to debug `malloc`. Suddenly a latent bug that was there all along shows itself in release, but fails to reproduce in debug. With the randomized behavior you describe in golang, the bug probably will show in debug and be caught.
- wutbrodo 8y agoYea I wasn't sure enough to make a stronger claim, but I don't believe I've ever used ordered iteration of a hashtable. I feel like if I was tempted to do so, it would prompt me to rethink my design. Call it an "algorithm smell"