mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 18:36:30 +02:00
31 lines
591 B
Go
31 lines
591 B
Go
package sets
|
|
|
|
// A Hash is a set implemented via a map.
|
|
type Hash[T comparable] struct {
|
|
m map[T]struct{}
|
|
}
|
|
|
|
// NewHash creates a new Hash set.
|
|
func NewHash[T comparable]() *Hash[T] {
|
|
return &Hash[T]{
|
|
m: make(map[T]struct{}),
|
|
}
|
|
}
|
|
|
|
// Add adds a value to the set.
|
|
func (s *Hash[T]) Add(elements ...T) {
|
|
for _, element := range elements {
|
|
s.m[element] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// Has returns true if the element is in the set.
|
|
func (s *Hash[T]) Has(element T) bool {
|
|
_, ok := s.m[element]
|
|
return ok
|
|
}
|
|
|
|
// Size returns the size of the set.
|
|
func (s *Hash[T]) Size() int {
|
|
return len(s.m)
|
|
}
|