Files
teleport/integrations/lib/stringset/stringset.go
T
Justinas Stankevičius 6af6e7f566 Vendor slack plugin and supporting libraries (#23045)
* Vendor slack plugin and supporting libraries

* Fix up plugin integration tests (wip)

* Run GCI on vendored code

* Use newtype instead of type alias

golangci-lint currently panics on this,
"skip-files" et al don't help, as it is a linter panic, not an error

See https://github.com/dominikh/go-tools/commit/d717045480130461e1e777ead7f2981621f0d9f0

* Remove long-runing plugins tests from difftest

* Move access plugin tests to unit-tests-integrations
2023-03-22 19:39:07 +00:00

66 lines
1.7 KiB
Go

// Copyright 2023 Gravitational, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package stringset
// StringSet is string container in which every string is contained at most once i.e. a set data structure.
type StringSet map[string]struct{}
// New builds a string set with elements from a given slice.
func New(elems ...string) StringSet {
set := NewWithCap(len(elems))
set.Add(elems...)
return set
}
// NewWithCap builds an empty string set with a given capacity.
func NewWithCap(cap int) StringSet {
return make(StringSet, cap)
}
// Add inserts a string to the set.
func (set StringSet) Add(elems ...string) {
for _, str := range elems {
set[str] = struct{}{}
}
}
// Del removes a string from the set.
func (set StringSet) Del(str string) {
delete(set, str)
}
// Len returns a set size.
func (set StringSet) Len() int {
return len(set)
}
// Contains checks if the set includes a given string.
func (set StringSet) Contains(str string) bool {
_, ok := set[str]
return ok
}
// ToSlice returns a slice with set contents.
func (set StringSet) ToSlice() []string {
if n := set.Len(); n > 0 {
result := make([]string, 0, n)
for str := range set {
result = append(result, str)
}
return result
}
return nil
}