Files
kopia/tests/robustness/snapmeta/index.go
Jarek Kowalski 8a4ac4dec3 Upgraded linter to 1.43.0 (#1505)
* fixed new gocritic violations
* fixed new 'contextcheck' violations
* fixed 'gosec' warnings
* suppressed ireturn and varnamelen linters
* fixed tenv violations, enabled building robustness tests on arm64
* fixed remaining linux failures
* makefile: fixed 'lint-all' target when running on arm64
* linter: increase deadline
* disable nilnil linter - to be enabled in separate PR
2021-11-11 17:03:11 -08:00

51 lines
1.1 KiB
Go

//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta
// Index is a map of index name to the keys associated
// with that index name.
type Index map[string]map[string]struct{}
// AddToIndex adds a key to the index of the given name.
func (idx Index) AddToIndex(key, indexName string) {
if _, ok := idx[indexName]; !ok {
idx[indexName] = make(map[string]struct{})
}
idx[indexName][key] = struct{}{}
}
// RemoveFromIndex removes a key from the index of the given name.
func (idx Index) RemoveFromIndex(key, indexName string) {
if _, ok := idx[indexName]; !ok {
return
}
delete(idx[indexName], key)
}
// GetKeys returns the list of keys associated with the given index name.
func (idx Index) GetKeys(indexName string) (ret []string) {
if _, ok := idx[indexName]; !ok {
return ret
}
for k := range idx[indexName] {
ret = append(ret, k)
}
return ret
}
// IsKeyInIndex will return true if the given index name contains the
// provided key.
func (idx Index) IsKeyInIndex(key, indexName string) bool {
if _, ok := idx[indexName]; ok {
_, keyExists := idx[indexName][key]
return keyExists
}
return false
}