Skip to content

Instantly share code, notes, and snippets.

@cvvs

cvvs/Map as a set

Created May 31, 2016
Embed
What would you like to do?
package main
import "fmt"
func main() {
var stringSet map[string]interface{} = make(map[string]interface{})
stringSet["apple"] = nil
stringSet["orange"] = nil
stringSet["cherry"] = nil
// O(1) vs O(n). Only matters for large lists
if _, ok := stringSet["apple"]; !ok {
fmt.Println("apple not in stringset")
}
if _, ok := stringSet["banana"]; !ok {
fmt.Println("banana not in stringset")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.