Revision 470b3207efe07c66126db88e682aced94df450f5 authored by Nicolas Busseneau on 26 April 2023, 17:13:46 UTC, committed by Nicolas Busseneau on 26 April 2023, 17:13:46 UTC
Signed-off-by: Nicolas Busseneau <nicolas@isovalent.com>
1 parent b016532
string.go
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package counter
// StringCounter tracks references for strings.
//
// No threadsafety is provided within this structure, the user is expected to
// handle concurrent access to this structure if it is used from multiple
// threads.
type StringCounter map[string]int
// Add increments the reference count for the specified string key.
func (s StringCounter) Add(key string) (changed bool) {
value, exists := s[key]
if !exists {
changed = true
}
s[key] = value + 1
return changed
}
// Delete decrements the reference count for the specified string key.
func (s StringCounter) Delete(key string) bool {
value := s[key]
if value <= 1 {
delete(s, key)
return true
}
s[key] = value - 1
return false
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...