diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-26 14:53:37 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-30 22:15:06 -0700 |
commit | 86063b41fc1a235930d6c79e6b7cd38ae8d8c147 (patch) | |
tree | 5c6b523a1c24062bbaba60bca1b7042b9976701c /lib/containers/syncmap.go | |
parent | f4f062d7d4ed730411e04ecd36ee36387e50739c (diff) |
Split lib/containers.Sync* to git.lukeshu.com/go/typedsync
Diffstat (limited to 'lib/containers/syncmap.go')
-rw-r--r-- | lib/containers/syncmap.go | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/lib/containers/syncmap.go b/lib/containers/syncmap.go deleted file mode 100644 index 74da4b3..0000000 --- a/lib/containers/syncmap.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com> -// -// SPDX-License-Identifier: GPL-2.0-or-later - -package containers - -import ( - "sync" -) - -type SyncMap[K comparable, V any] struct { - inner sync.Map -} - -func (m *SyncMap[K, V]) Delete(key K) { - m.inner.Delete(key) -} - -func (m *SyncMap[K, V]) Load(key K) (value V, ok bool) { - _value, ok := m.inner.Load(key) - if ok { - //nolint:forcetypeassert // Typed wrapper around untyped lib. - value = _value.(V) - } - return value, ok -} - -func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool) { - _value, ok := m.inner.LoadAndDelete(key) - if ok { - //nolint:forcetypeassert // Typed wrapper around untyped lib. - value = _value.(V) - } - return value, ok -} - -func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) { - _actual, loaded := m.inner.LoadOrStore(key, value) - //nolint:forcetypeassert // Typed wrapper around untyped lib. - actual = _actual.(V) - return actual, loaded -} - -func (m *SyncMap[K, V]) Range(f func(key K, value V) bool) { - m.inner.Range(func(key, value any) bool { - //nolint:forcetypeassert // Typed wrapper around untyped lib. - return f(key.(K), value.(V)) - }) -} - -func (m *SyncMap[K, V]) Store(key K, value V) { - m.inner.Store(key, value) -} |