package main
import("fmt""unsafe")type Set map[string]struct{}func(s Set)Append(v string){
s[v]=struct{}{}}func(s Set)Delete(v string){delete(s, v)}func(s Set)Exist(v string)bool{_, ok := s[v]return ok
}funcmain(){var t1 struct{}
t2 :=struct{
a uint32
b uint64
c uint32}{1,1,1}
t3 :=struct{
a uint64
b uint32
c uint32}{1,1,1}// 空结构体不占用内存,糟糕的成员变量顺序,正确的成员变量顺序
fmt.Println(unsafe.Sizeof(t1), unsafe.Sizeof(t2), unsafe.Sizeof(t3))
s := Set{}// 不管增加多少个成员函数,s的初始内存就占用这么大
fmt.Println(unsafe.Sizeof(s))
s.Append("a")
s.Append("a")
s.Append("b")
s.Delete("b")
fmt.Println(s.Exist("a"), s.Exist("b"))}