github.com/diamondburned/arikawa@v1.3.14/internal/moreatomic/guildid_set.go (about) 1 package moreatomic 2 3 import ( 4 "sync" 5 6 "github.com/diamondburned/arikawa/discord" 7 ) 8 9 type GuildIDSet struct { 10 set map[discord.GuildID]struct{} 11 mut sync.Mutex 12 } 13 14 // NewGuildIDSet creates a new GuildIDSet. 15 func NewGuildIDSet() *GuildIDSet { 16 return &GuildIDSet{ 17 set: make(map[discord.GuildID]struct{}), 18 } 19 } 20 21 // Add adds the passed discord.GuildID to the set. 22 func (s *GuildIDSet) Add(flake discord.GuildID) { 23 s.mut.Lock() 24 25 s.set[flake] = struct{}{} 26 27 s.mut.Unlock() 28 } 29 30 // Contains checks whether the passed discord.GuildID is present in the set. 31 func (s *GuildIDSet) Contains(flake discord.GuildID) (ok bool) { 32 s.mut.Lock() 33 defer s.mut.Unlock() 34 35 _, ok = s.set[flake] 36 return 37 } 38 39 // Delete deletes the passed discord.GuildID from the set and returns true if 40 // the element is present. If not, Delete is a no-op and returns false. 41 func (s *GuildIDSet) Delete(flake discord.GuildID) bool { 42 s.mut.Lock() 43 defer s.mut.Unlock() 44 45 if _, ok := s.set[flake]; ok { 46 delete(s.set, flake) 47 return true 48 } 49 50 return false 51 }