diff options
-rw-r--r-- | .golangci.yml | 1 | ||||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | syncutil/cachemap.go (renamed from cachemap.go) | 20 | ||||
-rw-r--r-- | syncutil/map_go118.go | 9 | ||||
-rw-r--r-- | syncutil/map_go120.go | 9 | ||||
-rw-r--r-- | typedsync/map.go (renamed from map.go) | 0 | ||||
-rw-r--r-- | typedsync/map_go118.go (renamed from map_go118.go) | 0 | ||||
-rw-r--r-- | typedsync/map_go120.go (renamed from map_go120.go) | 0 | ||||
-rw-r--r-- | typedsync/pool.go (renamed from pool.go) | 0 | ||||
-rw-r--r-- | typedsync/value.go (renamed from value.go) | 0 |
10 files changed, 31 insertions, 10 deletions
diff --git a/.golangci.yml b/.golangci.yml index 1cd4c02..841866d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -37,6 +37,7 @@ linters-settings: sections: - standard - default + - prefix(git.lukeshu.com/go/containers) gofmt: simplify: true gosec: @@ -1,3 +1,3 @@ -module git.lukeshu.com/go/typedsync +module git.lukeshu.com/go/containers go 1.18 diff --git a/cachemap.go b/syncutil/cachemap.go index 3294aa2..8eab4bc 100644 --- a/cachemap.go +++ b/syncutil/cachemap.go @@ -2,10 +2,12 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -package typedsync +package syncutil import ( "sync" + + "git.lukeshu.com/go/containers/typedsync" ) type cacheVal[V any] struct { @@ -16,16 +18,16 @@ type cacheVal[V any] struct { // The techniques used by CacheMap are similar to the techniques used // by encoding/json's type cache. -// A CacheMap is similar to a Map, but also has a .LoadOrCompute -// sibling to .LoadOrStore. This is useful for caching the results of -// computation where it is undesirable for concurrent calls to -// duplicate work. +// A CacheMap is similar to a typedsync.Map, but also has a +// .LoadOrCompute sibling to .LoadOrStore. This is useful for caching +// the results of computation where it is undesirable for concurrent +// calls to duplicate work. // -// Compared to a plain Map, a CacheMap has both more space overhead -// and more time overhead. +// Compared to a plain typedsync.Map, a CacheMap has both more space +// overhead and more time overhead. type CacheMap[K mapkey, V any] struct { - inner Map[K, *cacheVal[V]] - pool Pool[*cacheVal[V]] + inner typedsync.Map[K, *cacheVal[V]] + pool typedsync.Pool[*cacheVal[V]] } func (m *CacheMap[K, V]) Delete(key K) { diff --git a/syncutil/map_go118.go b/syncutil/map_go118.go new file mode 100644 index 0000000..2e71015 --- /dev/null +++ b/syncutil/map_go118.go @@ -0,0 +1,9 @@ +// Copyright (C) 2023 Luke Shumaker <lukeshu@lukeshu.com> +// +// SPDX-License-Identifier: GPL-2.0-or-later + +//go:build !go1.20 + +package syncutil + +type mapkey = any diff --git a/syncutil/map_go120.go b/syncutil/map_go120.go new file mode 100644 index 0000000..d6f62c1 --- /dev/null +++ b/syncutil/map_go120.go @@ -0,0 +1,9 @@ +// Copyright (C) 2023 Luke Shumaker <lukeshu@lukeshu.com> +// +// SPDX-License-Identifier: GPL-2.0-or-later + +//go:build go1.20 + +package syncutil + +type mapkey = comparable diff --git a/map.go b/typedsync/map.go index 6bb1170..6bb1170 100644 --- a/map.go +++ b/typedsync/map.go diff --git a/map_go118.go b/typedsync/map_go118.go index 5446c88..5446c88 100644 --- a/map_go118.go +++ b/typedsync/map_go118.go diff --git a/map_go120.go b/typedsync/map_go120.go index 0d4ff5b..0d4ff5b 100644 --- a/map_go120.go +++ b/typedsync/map_go120.go diff --git a/pool.go b/typedsync/pool.go index c196085..c196085 100644 --- a/pool.go +++ b/typedsync/pool.go diff --git a/value.go b/typedsync/value.go index 99c8876..99c8876 100644 --- a/value.go +++ b/typedsync/value.go |