type set map[strings]bool
res := make(set)
res[value] = true
I believe that when a Python programmer comes to a Go list asking how to make something like a Python set, the primary concern is not duplicating any values. The OP may want to clarify if I'm wrong. Slices are much further from a set than a map in this regard.
type set map[string]bool
mySet := make(set)
// add a value v
mySet[v] = true
// check if v is in mySet
if mySet[v] { ...
Shawn Milochik:AckI believe that when a Python programmer comes to a Go list asking how to make something like a Python set, the primary concern is not duplicating any values. The OP may want to clarify if I'm wrong. Slices are much further from a set than a map in this regard.My intention is to have a 'set' data structure with (in this case) 2 methods* add an element to a set (with the special case for bulk insert at the beginning and occasional inserts later)* fast(!) check if an element is in the setIn my case, I will have about 10'000'000 elements, where every element is a short string (well a short byte array) - the result of an SHA1 hash of other date. As Go does not have a set type, I started with
type set map[string]bool
mySet := make(set)
// add a value v
mySet[v] = true
// check if v is in mySet
if mySet[v] { ...I have updated https://gist.github.com/MirkoDziadzka/a941b46e0b66035f1129 with the improvements I got from this discussion, mainly setting a size hint for the make(set) to speed up the bulk insert.If I could solve this problem better with other standard Go data structures, I would love to hear about this.GreetingsMirko
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.