Hacker News new | past | comments | ask | show | jobs | submit login
GoDS (Go Data Structures) (golang) (github.com)
16 points by japanac on June 27, 2016 | hide | past | web | favorite | 5 comments

Why use a hashmap vs the built in golang map?

these two are the same, since one uses the other. i agree with you as the author of gods, that if it fits your problem, then use golang map by all means. however, if you use golang map and realize that your problem needs the keys to be ordered, for which the ordering is randomized in golang, then having used hashmap in the first place would allow you to easily switch to treemap without any changes to your code, since both implement the same interface. implementing a treemap, consequently also a red-black tree, is something i wouldn't do again. keeping the keys sorted in another golang's native structure is also cumbersome and will lead to consistency issues and unnecessary memory usage. in short: use the data structure that fits your problem, golang native, gods or other. gods attempts to provide well-defined shareable structure for various data structures as to eliminate the need to write that boilerplate logic all over.

consider an even simpler example of wanting an array that contains no duplicates and is sorted. i can write the logic for that in 5 minutes, but it will be bother memory and cpu inefficient. i would spend another 20 minutes optimizing that logic. by the time i'm done with that, i've forgotten why i needed that in the first place. importing gods' treeset would have been a lot easier, since it solves that problem.

The hashmap in GoDS is actually implemented using the go's native map, so there probably aren't any major differences. You just access map's methods in more OOP-like fashin (separate methods for Put, Get... instead of map[key]=value and value,find=map[key]...)

i'm not sure this is the right direction for golang. Sounds like you are fixing something that isn't broken.

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