1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-12-02 20:02:53 +00:00
arikawa/internal/moreatomic/guildid_set.go
Maximilian von Lindern 32789bb6e2 *: Separate utils and internal (#129)
* Utils: move package utils/heart to internal/heart

* Utils: move package utils/moreatomic to internal/moreatomic

* Utils: move package utils/zlib to internal/zlib
2020-07-29 16:58:33 -07:00

52 lines
1,020 B
Go

package moreatomic
import (
"sync"
"github.com/diamondburned/arikawa/discord"
)
type GuildIDSet struct {
set map[discord.GuildID]struct{}
mut sync.Mutex
}
// NewGuildIDSet creates a new GuildIDSet.
func NewGuildIDSet() *GuildIDSet {
return &GuildIDSet{
set: make(map[discord.GuildID]struct{}),
}
}
// Add adds the passed discord.GuildID to the set.
func (s *GuildIDSet) Add(flake discord.GuildID) {
s.mut.Lock()
s.set[flake] = struct{}{}
s.mut.Unlock()
}
// Contains checks whether the passed discord.GuildID is present in the set.
func (s *GuildIDSet) Contains(flake discord.GuildID) (ok bool) {
s.mut.Lock()
defer s.mut.Unlock()
_, ok = s.set[flake]
return
}
// Delete deletes the passed discord.GuildID from the set and returns true if
// the element is present. If not, Delete is a no-op and returns false.
func (s *GuildIDSet) Delete(flake discord.GuildID) bool {
s.mut.Lock()
defer s.mut.Unlock()
if _, ok := s.set[flake]; ok {
delete(s.set, flake)
return true
}
return false
}