diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 630106b7c0..bb093ece7d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -94,7 +94,7 @@ jobs: go-version: 1.13 - name: Install proto-gen-go run: go get -u github.com/golang/protobuf/protoc-gen-go@v1.3.3 - - name: Install proto-gen-go + - name: Install go-syncmap run: go get github.com/searKing/golang/tools/cmd/go-syncmap - name: Generate files run: go generate ./... diff --git a/pkg/networkservice/common/externalips/string_map.gen.go b/pkg/networkservice/common/externalips/string_map.gen.go index 6dda70aaf0..c561806783 100644 --- a/pkg/networkservice/common/externalips/string_map.gen.go +++ b/pkg/networkservice/common/externalips/string_map.gen.go @@ -1,9 +1,11 @@ -// Code generated by "go-syncmap -output string_map.gen.go -type stringMap"; DO NOT EDIT. - +// Code generated by "-output string_map.gen.go -type stringMap -output string_map.gen.go -type stringMap"; DO NOT EDIT. package externalips -import "sync" +import ( + "sync" // Used by sync.Map. +) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert stringMap literal (type stringMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. @@ -12,10 +14,25 @@ func _() { var _nil_stringMap_string_value = func() (val string) { return }() +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *stringMap) Load(key string) (string, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_stringMap_string_value, ok + } + return value.(string), ok +} + +// Store sets the value for a key. func (m *stringMap) Store(key string, value string) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *stringMap) LoadOrStore(key string, value string) (string, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { @@ -24,18 +41,31 @@ func (m *stringMap) LoadOrStore(key string, value string) (string, bool) { return actual.(string), loaded } -func (m *stringMap) Load(key string) (string, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_stringMap_string_value, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *stringMap) LoadAndDelete(key string) (value string, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_stringMap_string_value, loaded } - return value.(string), ok + return actual.(string), loaded } +// Delete deletes the value for a key. func (m *stringMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *stringMap) Range(f func(key string, value string) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(string)) diff --git a/pkg/networkservice/common/interpose/connection_info_map.gen.go b/pkg/networkservice/common/interpose/connection_info_map.gen.go index 0fecd3532e..1909e42cb4 100644 --- a/pkg/networkservice/common/interpose/connection_info_map.gen.go +++ b/pkg/networkservice/common/interpose/connection_info_map.gen.go @@ -1,9 +1,11 @@ -// Code generated by "go-syncmap -output connection_info_map.gen.go -type connectionInfoMap"; DO NOT EDIT. - +// Code generated by "-output connection_info_map.gen.go -type connectionInfoMap -output connection_info_map.gen.go -type connectionInfoMap"; DO NOT EDIT. package interpose -import "sync" +import ( + "sync" // Used by sync.Map. +) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert connectionInfoMap literal (type connectionInfoMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. @@ -12,10 +14,25 @@ func _() { var _nil_connectionInfoMap_connectionInfo_value = func() (val connectionInfo) { return }() +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *connectionInfoMap) Load(key string) (connectionInfo, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_connectionInfoMap_connectionInfo_value, ok + } + return value.(connectionInfo), ok +} + +// Store sets the value for a key. func (m *connectionInfoMap) Store(key string, value connectionInfo) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *connectionInfoMap) LoadOrStore(key string, value connectionInfo) (connectionInfo, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { @@ -24,18 +41,31 @@ func (m *connectionInfoMap) LoadOrStore(key string, value connectionInfo) (conne return actual.(connectionInfo), loaded } -func (m *connectionInfoMap) Load(key string) (connectionInfo, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_connectionInfoMap_connectionInfo_value, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *connectionInfoMap) LoadAndDelete(key string) (value connectionInfo, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_connectionInfoMap_connectionInfo_value, loaded } - return value.(connectionInfo), ok + return actual.(connectionInfo), loaded } +// Delete deletes the value for a key. func (m *connectionInfoMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *connectionInfoMap) Range(f func(key string, value connectionInfo) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(connectionInfo)) diff --git a/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go b/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go index d9a0fcf3bb..b43f44eea4 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go +++ b/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go @@ -1,38 +1,71 @@ -// Code generated by "go-syncmap -output per_connection_file_map.gen.go -type perConnectionFileMapMap"; DO NOT EDIT. - +// Code generated by "-output per_connection_file_map.gen.go -type perConnectionFileMapMap -output per_connection_file_map.gen.go -type perConnectionFileMapMap"; DO NOT EDIT. package recvfd -import "sync" +import ( + "sync" // Used by sync.Map. +) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert perConnectionFileMapMap literal (type perConnectionFileMapMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(perConnectionFileMapMap{}) } + +var _nil_perConnectionFileMapMap_perConnectionFileMap_value = func() (val *perConnectionFileMap) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *perConnectionFileMapMap) Load(key string) (*perConnectionFileMap, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_perConnectionFileMapMap_perConnectionFileMap_value, ok + } + return value.(*perConnectionFileMap), ok +} + +// Store sets the value for a key. func (m *perConnectionFileMapMap) Store(key string, value *perConnectionFileMap) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *perConnectionFileMapMap) LoadOrStore(key string, value *perConnectionFileMap) (*perConnectionFileMap, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_perConnectionFileMapMap_perConnectionFileMap_value, loaded } return actual.(*perConnectionFileMap), loaded } -func (m *perConnectionFileMapMap) Load(key string) (*perConnectionFileMap, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *perConnectionFileMapMap) LoadAndDelete(key string) (value *perConnectionFileMap, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_perConnectionFileMapMap_perConnectionFileMap_value, loaded } - return value.(*perConnectionFileMap), ok + return actual.(*perConnectionFileMap), loaded } +// Delete deletes the value for a key. func (m *perConnectionFileMapMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *perConnectionFileMapMap) Range(f func(key string, value *perConnectionFileMap) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*perConnectionFileMap)) diff --git a/pkg/networkservice/common/timeout/README.md b/pkg/networkservice/common/timeout/README.md index 4090b68b30..3cfd6b4e15 100644 --- a/pkg/networkservice/common/timeout/README.md +++ b/pkg/networkservice/common/timeout/README.md @@ -7,10 +7,10 @@ previous NSM-based application. For such case connection should be closed. ## timeoutServer -timeoutServer keeps timers [timeout.timerMap](https://github.com/networkservicemesh/sdk/blob/master/pkg/networkservice/common/timeout/gen.go#L27) +timeoutServer keeps timers [timeout.timerMap](https://github.com/networkservicemesh/sdk/blob/master/pkg/networkservice/common/timeout/gen.go#L26) mapping incoming request Connection.ID to a timeout timer firing Close on the subsequent chain after the connection previous path element expires. To prevent simultaneous execution of multiple Request, Close event for the same Connection.ID in parallel -it also keeps executors [timeout.executorMap](https://github.com/networkservicemesh/sdk/blob/master/pkg/networkservice/common/timeout/gen.go#L37) +it also keeps executors [timeout.executorMap](https://github.com/networkservicemesh/sdk/blob/master/pkg/networkservice/common/timeout/gen.go#L27) mapping request Connection.ID to an executor for serializing all Request, Close event for the mapped Connection.ID. timeoutServer closes only subsequent chain elements and uses base context for the Close. So all the chain elements in diff --git a/pkg/networkservice/common/timeout/executor_map.gen.go b/pkg/networkservice/common/timeout/executor_map.gen.go index 615ba1b14d..ddd3c86a13 100644 --- a/pkg/networkservice/common/timeout/executor_map.gen.go +++ b/pkg/networkservice/common/timeout/executor_map.gen.go @@ -1,42 +1,73 @@ -// Code generated by "go-syncmap -output executor_map.gen.go -type executorMap"; DO NOT EDIT. - +// Code generated by "-output executor_map.gen.go -type executorMap -output executor_map.gen.go -type executorMap"; DO NOT EDIT. package timeout import ( - "sync" + "sync" // Used by sync.Map. "github.com/edwarnicke/serialize" ) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert executorMap literal (type executorMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(executorMap{}) } + +var _nil_executorMap_serialize_Executor_value = func() (val *serialize.Executor) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *executorMap) Load(key string) (*serialize.Executor, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_executorMap_serialize_Executor_value, ok + } + return value.(*serialize.Executor), ok +} + +// Store sets the value for a key. func (m *executorMap) Store(key string, value *serialize.Executor) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *executorMap) LoadOrStore(key string, value *serialize.Executor) (*serialize.Executor, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_executorMap_serialize_Executor_value, loaded } return actual.(*serialize.Executor), loaded } -func (m *executorMap) Load(key string) (*serialize.Executor, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *executorMap) LoadAndDelete(key string) (value *serialize.Executor, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_executorMap_serialize_Executor_value, loaded } - return value.(*serialize.Executor), ok + return actual.(*serialize.Executor), loaded } +// Delete deletes the value for a key. func (m *executorMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *executorMap) Range(f func(key string, value *serialize.Executor) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*serialize.Executor)) diff --git a/pkg/networkservice/common/timeout/gen.go b/pkg/networkservice/common/timeout/gen.go index 83987f02d5..b8573f453d 100644 --- a/pkg/networkservice/common/timeout/gen.go +++ b/pkg/networkservice/common/timeout/gen.go @@ -18,20 +18,10 @@ package timeout import ( "sync" - "time" ) //go:generate go-syncmap -output timer_map.gen.go -type timerMap //go:generate go-syncmap -output executor_map.gen.go -type executorMap type timerMap sync.Map - -func (m *timerMap) LoadAndDelete(key string) (*time.Timer, bool) { - value, loaded := (*sync.Map)(m).LoadAndDelete(key) - if value == nil { - return nil, loaded - } - return value.(*time.Timer), loaded -} - type executorMap sync.Map diff --git a/pkg/networkservice/common/timeout/timer_map.gen.go b/pkg/networkservice/common/timeout/timer_map.gen.go index 201d6857a1..6763ec3d47 100644 --- a/pkg/networkservice/common/timeout/timer_map.gen.go +++ b/pkg/networkservice/common/timeout/timer_map.gen.go @@ -1,41 +1,72 @@ -// Code generated by "go-syncmap -output timer_map.gen.go -type timerMap"; DO NOT EDIT. - +// Code generated by "-output timer_map.gen.go -type timerMap -output timer_map.gen.go -type timerMap"; DO NOT EDIT. package timeout import ( - "sync" + "sync" // Used by sync.Map. "time" ) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert timerMap literal (type timerMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(timerMap{}) } + +var _nil_timerMap_time_Timer_value = func() (val *time.Timer) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *timerMap) Load(key string) (*time.Timer, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_timerMap_time_Timer_value, ok + } + return value.(*time.Timer), ok +} + +// Store sets the value for a key. func (m *timerMap) Store(key string, value *time.Timer) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *timerMap) LoadOrStore(key string, value *time.Timer) (*time.Timer, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_timerMap_time_Timer_value, loaded } return actual.(*time.Timer), loaded } -func (m *timerMap) Load(key string) (*time.Timer, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *timerMap) LoadAndDelete(key string) (value *time.Timer, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_timerMap_time_Timer_value, loaded } - return value.(*time.Timer), ok + return actual.(*time.Timer), loaded } +// Delete deletes the value for a key. func (m *timerMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *timerMap) Range(f func(key string, value *time.Timer) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*time.Timer)) diff --git a/pkg/registry/common/connect/ns_sync_map.gen.go b/pkg/registry/common/connect/ns_sync_map.gen.go index aa9da4753d..59de755535 100644 --- a/pkg/registry/common/connect/ns_sync_map.gen.go +++ b/pkg/registry/common/connect/ns_sync_map.gen.go @@ -1,38 +1,71 @@ -// Code generated by "go-syncmap -output ns_sync_map.gen.go -type nsClientMap"; DO NOT EDIT. - +// Code generated by "-output ns_sync_map.gen.go -type nsClientMap -output ns_sync_map.gen.go -type nsClientMap"; DO NOT EDIT. package connect -import "sync" +import ( + "sync" // Used by sync.Map. +) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert nsClientMap literal (type nsClientMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(nsClientMap{}) } + +var _nil_nsClientMap_nsCacheEntry_value = func() (val *nsCacheEntry) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *nsClientMap) Load(key string) (*nsCacheEntry, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_nsClientMap_nsCacheEntry_value, ok + } + return value.(*nsCacheEntry), ok +} + +// Store sets the value for a key. func (m *nsClientMap) Store(key string, value *nsCacheEntry) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *nsClientMap) LoadOrStore(key string, value *nsCacheEntry) (*nsCacheEntry, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_nsClientMap_nsCacheEntry_value, loaded } return actual.(*nsCacheEntry), loaded } -func (m *nsClientMap) Load(key string) (*nsCacheEntry, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *nsClientMap) LoadAndDelete(key string) (value *nsCacheEntry, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_nsClientMap_nsCacheEntry_value, loaded } - return value.(*nsCacheEntry), ok + return actual.(*nsCacheEntry), loaded } +// Delete deletes the value for a key. func (m *nsClientMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *nsClientMap) Range(f func(key string, value *nsCacheEntry) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*nsCacheEntry)) diff --git a/pkg/registry/common/connect/nse_sync_map.gen.go b/pkg/registry/common/connect/nse_sync_map.gen.go index 648f2c3dc9..b84f2d1069 100644 --- a/pkg/registry/common/connect/nse_sync_map.gen.go +++ b/pkg/registry/common/connect/nse_sync_map.gen.go @@ -1,38 +1,71 @@ -// Code generated by "go-syncmap -output nse_sync_map.gen.go -type nseClientMap"; DO NOT EDIT. - +// Code generated by "-output nse_sync_map.gen.go -type nseClientMap -output nse_sync_map.gen.go -type nseClientMap"; DO NOT EDIT. package connect -import "sync" +import ( + "sync" // Used by sync.Map. +) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert nseClientMap literal (type nseClientMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(nseClientMap{}) } + +var _nil_nseClientMap_nseCacheEntry_value = func() (val *nseCacheEntry) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *nseClientMap) Load(key string) (*nseCacheEntry, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_nseClientMap_nseCacheEntry_value, ok + } + return value.(*nseCacheEntry), ok +} + +// Store sets the value for a key. func (m *nseClientMap) Store(key string, value *nseCacheEntry) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *nseClientMap) LoadOrStore(key string, value *nseCacheEntry) (*nseCacheEntry, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_nseClientMap_nseCacheEntry_value, loaded } return actual.(*nseCacheEntry), loaded } -func (m *nseClientMap) Load(key string) (*nseCacheEntry, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *nseClientMap) LoadAndDelete(key string) (value *nseCacheEntry, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_nseClientMap_nseCacheEntry_value, loaded } - return value.(*nseCacheEntry), ok + return actual.(*nseCacheEntry), loaded } +// Delete deletes the value for a key. func (m *nseClientMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *nseClientMap) Range(f func(key string, value *nseCacheEntry) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*nseCacheEntry)) diff --git a/pkg/registry/common/endpointurls/sync_set.gen.go b/pkg/registry/common/endpointurls/sync_set.gen.go index 15efb46693..feb7791e04 100644 --- a/pkg/registry/common/endpointurls/sync_set.gen.go +++ b/pkg/registry/common/endpointurls/sync_set.gen.go @@ -1,12 +1,12 @@ -// Code generated by "go-syncmap -output sync_set.gen.go -type Set"; DO NOT EDIT. - +// Code generated by "-output sync_set.gen.go -type Set -output sync_set.gen.go -type Set"; DO NOT EDIT. package endpointurls import ( "net/url" - "sync" + "sync" // Used by sync.Map. ) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert Set literal (type Set) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. @@ -15,10 +15,25 @@ func _() { var _nil_Set_struct___value = func() (val struct{}) { return }() +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *Set) Load(key url.URL) (struct{}, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_Set_struct___value, ok + } + return value.(struct{}), ok +} + +// Store sets the value for a key. func (m *Set) Store(key url.URL, value struct{}) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *Set) LoadOrStore(key url.URL, value struct{}) (struct{}, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { @@ -27,18 +42,31 @@ func (m *Set) LoadOrStore(key url.URL, value struct{}) (struct{}, bool) { return actual.(struct{}), loaded } -func (m *Set) Load(key url.URL) (struct{}, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_Set_struct___value, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *Set) LoadAndDelete(key url.URL) (value struct{}, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_Set_struct___value, loaded } - return value.(struct{}), ok + return actual.(struct{}), loaded } +// Delete deletes the value for a key. func (m *Set) Delete(key url.URL) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *Set) Range(f func(key url.URL, value struct{}) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(url.URL), value.(struct{})) diff --git a/pkg/registry/common/expire/context_sync_map.gen.go b/pkg/registry/common/expire/context_sync_map.gen.go index 711bd5f8ea..0b133c47dc 100644 --- a/pkg/registry/common/expire/context_sync_map.gen.go +++ b/pkg/registry/common/expire/context_sync_map.gen.go @@ -1,12 +1,12 @@ -// Code generated by "go-syncmap -output context_sync_map.gen.go -type contextMap"; DO NOT EDIT. - +// Code generated by "-output context_sync_map.gen.go -type contextMap -output context_sync_map.gen.go -type contextMap"; DO NOT EDIT. package expire import ( "context" - "sync" + "sync" // Used by sync.Map. ) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert contextMap literal (type contextMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. @@ -15,10 +15,25 @@ func _() { var _nil_contextMap_context_Context_value = func() (val context.Context) { return }() +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *contextMap) Load(key string) (context.Context, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_contextMap_context_Context_value, ok + } + return value.(context.Context), ok +} + +// Store sets the value for a key. func (m *contextMap) Store(key string, value context.Context) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *contextMap) LoadOrStore(key string, value context.Context) (context.Context, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { @@ -27,18 +42,31 @@ func (m *contextMap) LoadOrStore(key string, value context.Context) (context.Con return actual.(context.Context), loaded } -func (m *contextMap) Load(key string) (context.Context, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_contextMap_context_Context_value, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *contextMap) LoadAndDelete(key string) (value context.Context, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_contextMap_context_Context_value, loaded } - return value.(context.Context), ok + return actual.(context.Context), loaded } +// Delete deletes the value for a key. func (m *contextMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *contextMap) Range(f func(key string, value context.Context) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(context.Context)) diff --git a/pkg/registry/common/expire/int_sync_map.gen.go b/pkg/registry/common/expire/int_sync_map.gen.go index bed5429f34..b02d749c81 100644 --- a/pkg/registry/common/expire/int_sync_map.gen.go +++ b/pkg/registry/common/expire/int_sync_map.gen.go @@ -1,38 +1,71 @@ -// Code generated by "go-syncmap -output int_sync_map.gen.go -type intMap"; DO NOT EDIT. - +// Code generated by "-output int_sync_map.gen.go -type intMap -output int_sync_map.gen.go -type intMap"; DO NOT EDIT. package expire -import "sync" +import ( + "sync" // Used by sync.Map. +) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert intMap literal (type intMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(intMap{}) } + +var _nil_intMap_int32_value = func() (val *int32) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *intMap) Load(key string) (*int32, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_intMap_int32_value, ok + } + return value.(*int32), ok +} + +// Store sets the value for a key. func (m *intMap) Store(key string, value *int32) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *intMap) LoadOrStore(key string, value *int32) (*int32, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_intMap_int32_value, loaded } return actual.(*int32), loaded } -func (m *intMap) Load(key string) (*int32, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *intMap) LoadAndDelete(key string) (value *int32, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_intMap_int32_value, loaded } - return value.(*int32), ok + return actual.(*int32), loaded } +// Delete deletes the value for a key. func (m *intMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *intMap) Range(f func(key string, value *int32) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*int32)) diff --git a/pkg/registry/common/expire/timer_sync_map.gen.go b/pkg/registry/common/expire/timer_sync_map.gen.go index d7fe61299f..4f3ace474b 100644 --- a/pkg/registry/common/expire/timer_sync_map.gen.go +++ b/pkg/registry/common/expire/timer_sync_map.gen.go @@ -1,41 +1,72 @@ -// Code generated by "go-syncmap -output timer_sync_map.gen.go -type timerMap"; DO NOT EDIT. - +// Code generated by "-output timer_sync_map.gen.go -type timerMap -output timer_sync_map.gen.go -type timerMap"; DO NOT EDIT. package expire import ( - "sync" + "sync" // Used by sync.Map. "time" ) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert timerMap literal (type timerMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(timerMap{}) } + +var _nil_timerMap_time_Timer_value = func() (val *time.Timer) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *timerMap) Load(key string) (*time.Timer, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_timerMap_time_Timer_value, ok + } + return value.(*time.Timer), ok +} + +// Store sets the value for a key. func (m *timerMap) Store(key string, value *time.Timer) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *timerMap) LoadOrStore(key string, value *time.Timer) (*time.Timer, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_timerMap_time_Timer_value, loaded } return actual.(*time.Timer), loaded } -func (m *timerMap) Load(key string) (*time.Timer, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *timerMap) LoadAndDelete(key string) (value *time.Timer, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_timerMap_time_Timer_value, loaded } - return value.(*time.Timer), ok + return actual.(*time.Timer), loaded } +// Delete deletes the value for a key. func (m *timerMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *timerMap) Range(f func(key string, value *time.Timer) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*time.Timer)) diff --git a/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go b/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go index c0af9894ef..517157b87d 100644 --- a/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go +++ b/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go @@ -1,38 +1,71 @@ -// Code generated by "go-syncmap -output per_endpoint_file_map.gen.go -type perEndpointFileMapMap"; DO NOT EDIT. - +// Code generated by "-output per_endpoint_file_map.gen.go -type perEndpointFileMapMap -output per_endpoint_file_map.gen.go -type perEndpointFileMapMap"; DO NOT EDIT. package recvfd -import "sync" +import ( + "sync" // Used by sync.Map. +) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert perEndpointFileMapMap literal (type perEndpointFileMapMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(perEndpointFileMapMap{}) } + +var _nil_perEndpointFileMapMap_perEndpointFileMap_value = func() (val *perEndpointFileMap) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *perEndpointFileMapMap) Load(key string) (*perEndpointFileMap, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_perEndpointFileMapMap_perEndpointFileMap_value, ok + } + return value.(*perEndpointFileMap), ok +} + +// Store sets the value for a key. func (m *perEndpointFileMapMap) Store(key string, value *perEndpointFileMap) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *perEndpointFileMapMap) LoadOrStore(key string, value *perEndpointFileMap) (*perEndpointFileMap, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_perEndpointFileMapMap_perEndpointFileMap_value, loaded } return actual.(*perEndpointFileMap), loaded } -func (m *perEndpointFileMapMap) Load(key string) (*perEndpointFileMap, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *perEndpointFileMapMap) LoadAndDelete(key string) (value *perEndpointFileMap, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_perEndpointFileMapMap_perEndpointFileMap_value, loaded } - return value.(*perEndpointFileMap), ok + return actual.(*perEndpointFileMap), loaded } +// Delete deletes the value for a key. func (m *perEndpointFileMapMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *perEndpointFileMapMap) Range(f func(key string, value *perEndpointFileMap) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*perEndpointFileMap)) diff --git a/pkg/registry/common/refresh/sync_map.gen.go b/pkg/registry/common/refresh/sync_map.gen.go index 75e6e7c832..151c5b79de 100644 --- a/pkg/registry/common/refresh/sync_map.gen.go +++ b/pkg/registry/common/refresh/sync_map.gen.go @@ -1,12 +1,12 @@ -// Code generated by "go-syncmap -output sync_map.gen.go -type cancelsMap"; DO NOT EDIT. - +// Code generated by "-output sync_map.gen.go -type cancelsMap -output sync_map.gen.go -type cancelsMap"; DO NOT EDIT. package refresh import ( "context" - "sync" + "sync" // Used by sync.Map. ) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert cancelsMap literal (type cancelsMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. @@ -15,10 +15,25 @@ func _() { var _nil_cancelsMap_context_CancelFunc_value = func() (val context.CancelFunc) { return }() +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *cancelsMap) Load(key string) (context.CancelFunc, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_cancelsMap_context_CancelFunc_value, ok + } + return value.(context.CancelFunc), ok +} + +// Store sets the value for a key. func (m *cancelsMap) Store(key string, value context.CancelFunc) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *cancelsMap) LoadOrStore(key string, value context.CancelFunc) (context.CancelFunc, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { @@ -27,18 +42,31 @@ func (m *cancelsMap) LoadOrStore(key string, value context.CancelFunc) (context. return actual.(context.CancelFunc), loaded } -func (m *cancelsMap) Load(key string) (context.CancelFunc, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_cancelsMap_context_CancelFunc_value, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *cancelsMap) LoadAndDelete(key string) (value context.CancelFunc, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_cancelsMap_context_CancelFunc_value, loaded } - return value.(context.CancelFunc), ok + return actual.(context.CancelFunc), loaded } +// Delete deletes the value for a key. func (m *cancelsMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *cancelsMap) Range(f func(key string, value context.CancelFunc) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(context.CancelFunc)) diff --git a/pkg/registry/memory/ns_sync_map.gen.go b/pkg/registry/memory/ns_sync_map.gen.go index d5be7acbab..a038732818 100644 --- a/pkg/registry/memory/ns_sync_map.gen.go +++ b/pkg/registry/memory/ns_sync_map.gen.go @@ -1,42 +1,73 @@ -// Code generated by "go-syncmap -output ns_sync_map.gen.go -type NetworkServiceSyncMap"; DO NOT EDIT. - +// Code generated by "-output ns_sync_map.gen.go -type NetworkServiceSyncMap -output ns_sync_map.gen.go -type NetworkServiceSyncMap"; DO NOT EDIT. package memory import ( - "sync" + "sync" // Used by sync.Map. "github.com/networkservicemesh/api/pkg/api/registry" ) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert NetworkServiceSyncMap literal (type NetworkServiceSyncMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(NetworkServiceSyncMap{}) } + +var _nil_NetworkServiceSyncMap_registry_NetworkService_value = func() (val *registry.NetworkService) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *NetworkServiceSyncMap) Load(key string) (*registry.NetworkService, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_NetworkServiceSyncMap_registry_NetworkService_value, ok + } + return value.(*registry.NetworkService), ok +} + +// Store sets the value for a key. func (m *NetworkServiceSyncMap) Store(key string, value *registry.NetworkService) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *NetworkServiceSyncMap) LoadOrStore(key string, value *registry.NetworkService) (*registry.NetworkService, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_NetworkServiceSyncMap_registry_NetworkService_value, loaded } return actual.(*registry.NetworkService), loaded } -func (m *NetworkServiceSyncMap) Load(key string) (*registry.NetworkService, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *NetworkServiceSyncMap) LoadAndDelete(key string) (value *registry.NetworkService, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_NetworkServiceSyncMap_registry_NetworkService_value, loaded } - return value.(*registry.NetworkService), ok + return actual.(*registry.NetworkService), loaded } +// Delete deletes the value for a key. func (m *NetworkServiceSyncMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *NetworkServiceSyncMap) Range(f func(key string, value *registry.NetworkService) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*registry.NetworkService)) diff --git a/pkg/registry/memory/nse_sync_map.gen.go b/pkg/registry/memory/nse_sync_map.gen.go index 2e3d3ab292..4b1d664282 100644 --- a/pkg/registry/memory/nse_sync_map.gen.go +++ b/pkg/registry/memory/nse_sync_map.gen.go @@ -1,42 +1,73 @@ -// Code generated by "go-syncmap -output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap"; DO NOT EDIT. - +// Code generated by "-output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap -output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap"; DO NOT EDIT. package memory import ( - "sync" + "sync" // Used by sync.Map. "github.com/networkservicemesh/api/pkg/api/registry" ) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert NetworkServiceEndpointSyncMap literal (type NetworkServiceEndpointSyncMap) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(NetworkServiceEndpointSyncMap{}) } + +var _nil_NetworkServiceEndpointSyncMap_registry_NetworkServiceEndpoint_value = func() (val *registry.NetworkServiceEndpoint) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *NetworkServiceEndpointSyncMap) Load(key string) (*registry.NetworkServiceEndpoint, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_NetworkServiceEndpointSyncMap_registry_NetworkServiceEndpoint_value, ok + } + return value.(*registry.NetworkServiceEndpoint), ok +} + +// Store sets the value for a key. func (m *NetworkServiceEndpointSyncMap) Store(key string, value *registry.NetworkServiceEndpoint) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *NetworkServiceEndpointSyncMap) LoadOrStore(key string, value *registry.NetworkServiceEndpoint) (*registry.NetworkServiceEndpoint, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_NetworkServiceEndpointSyncMap_registry_NetworkServiceEndpoint_value, loaded } return actual.(*registry.NetworkServiceEndpoint), loaded } -func (m *NetworkServiceEndpointSyncMap) Load(key string) (*registry.NetworkServiceEndpoint, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *NetworkServiceEndpointSyncMap) LoadAndDelete(key string) (value *registry.NetworkServiceEndpoint, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_NetworkServiceEndpointSyncMap_registry_NetworkServiceEndpoint_value, loaded } - return value.(*registry.NetworkServiceEndpoint), ok + return actual.(*registry.NetworkServiceEndpoint), loaded } +// Delete deletes the value for a key. func (m *NetworkServiceEndpointSyncMap) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *NetworkServiceEndpointSyncMap) Range(f func(key string, value *registry.NetworkServiceEndpoint) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*registry.NetworkServiceEndpoint)) diff --git a/pkg/tools/clientmap/clientmap.gen.go b/pkg/tools/clientmap/clientmap.gen.go index 850565bd21..0c16031716 100644 --- a/pkg/tools/clientmap/clientmap.gen.go +++ b/pkg/tools/clientmap/clientmap.gen.go @@ -1,13 +1,13 @@ -// Code generated by "go-syncmap -output clientmap.gen.go -type Map"; DO NOT EDIT. - +// Code generated by "-output clientmap.gen.go -type Map -output clientmap.gen.go -type Map"; DO NOT EDIT. package clientmap import ( - "sync" + "sync" // Used by sync.Map. "github.com/networkservicemesh/api/pkg/api/networkservice" ) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert Map literal (type Map) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. @@ -16,10 +16,25 @@ func _() { var _nil_Map_networkservice_NetworkServiceClient_value = func() (val networkservice.NetworkServiceClient) { return }() +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *Map) Load(key string) (networkservice.NetworkServiceClient, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_Map_networkservice_NetworkServiceClient_value, ok + } + return value.(networkservice.NetworkServiceClient), ok +} + +// Store sets the value for a key. func (m *Map) Store(key string, value networkservice.NetworkServiceClient) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *Map) LoadOrStore(key string, value networkservice.NetworkServiceClient) (networkservice.NetworkServiceClient, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { @@ -28,18 +43,31 @@ func (m *Map) LoadOrStore(key string, value networkservice.NetworkServiceClient) return actual.(networkservice.NetworkServiceClient), loaded } -func (m *Map) Load(key string) (networkservice.NetworkServiceClient, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_Map_networkservice_NetworkServiceClient_value, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *Map) LoadAndDelete(key string) (value networkservice.NetworkServiceClient, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_Map_networkservice_NetworkServiceClient_value, loaded } - return value.(networkservice.NetworkServiceClient), ok + return actual.(networkservice.NetworkServiceClient), loaded } +// Delete deletes the value for a key. func (m *Map) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *Map) Range(f func(key string, value networkservice.NetworkServiceClient) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(networkservice.NetworkServiceClient)) diff --git a/pkg/tools/stringurl/sync_map.gen.go b/pkg/tools/stringurl/sync_map.gen.go index efd2c0b110..f1ce2ae89f 100644 --- a/pkg/tools/stringurl/sync_map.gen.go +++ b/pkg/tools/stringurl/sync_map.gen.go @@ -1,41 +1,72 @@ -// Code generated by "go-syncmap -output sync_map.gen.go -type Map"; DO NOT EDIT. - +// Code generated by "-output sync_map.gen.go -type Map -output sync_map.gen.go -type Map"; DO NOT EDIT. package stringurl import ( "net/url" - "sync" + "sync" // Used by sync.Map. ) +// Generate code that will fail if the constants change value. func _() { // An "cannot convert Map literal (type Map) to type sync.Map" compiler error signifies that the base type have changed. // Re-run the go-syncmap command to generate them again. _ = (sync.Map)(Map{}) } + +var _nil_Map_url_URL_value = func() (val *url.URL) { return }() + +// Load returns the value stored in the map for a key, or nil if no +// value is present. +// The ok result indicates whether value was found in the map. +func (m *Map) Load(key string) (*url.URL, bool) { + value, ok := (*sync.Map)(m).Load(key) + if value == nil { + return _nil_Map_url_URL_value, ok + } + return value.(*url.URL), ok +} + +// Store sets the value for a key. func (m *Map) Store(key string, value *url.URL) { (*sync.Map)(m).Store(key, value) } +// LoadOrStore returns the existing value for the key if present. +// Otherwise, it stores and returns the given value. +// The loaded result is true if the value was loaded, false if stored. func (m *Map) LoadOrStore(key string, value *url.URL) (*url.URL, bool) { actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) if actual == nil { - return nil, loaded + return _nil_Map_url_URL_value, loaded } return actual.(*url.URL), loaded } -func (m *Map) Load(key string) (*url.URL, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return nil, ok +// LoadAndDelete deletes the value for a key, returning the previous value if any. +// The loaded result reports whether the key was present. +func (m *Map) LoadAndDelete(key string) (value *url.URL, loaded bool) { + actual, loaded := (*sync.Map)(m).LoadAndDelete(key) + if actual == nil { + return _nil_Map_url_URL_value, loaded } - return value.(*url.URL), ok + return actual.(*url.URL), loaded } +// Delete deletes the value for a key. func (m *Map) Delete(key string) { (*sync.Map)(m).Delete(key) } +// Range calls f sequentially for each key and value present in the map. +// If f returns false, range stops the iteration. +// +// Range does not necessarily correspond to any consistent snapshot of the Map's +// contents: no key will be visited more than once, but if the value for any key +// is stored or deleted concurrently, Range may reflect any mapping for that key +// from any point during the Range call. +// +// Range may be O(N) with the number of elements in the map even if f returns +// false after a constant number of calls. func (m *Map) Range(f func(key string, value *url.URL) bool) { (*sync.Map)(m).Range(func(key, value interface{}) bool { return f(key.(string), value.(*url.URL))