mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-08-14 07:18:32 +02:00
Timer in go that syncs with random nodes in the mesh every
given time interval.
This commit is contained in:
22
pkg/lib/conv.go
Normal file
22
pkg/lib/conv.go
Normal file
@ -0,0 +1,22 @@
|
||||
package lib
|
||||
|
||||
// MapToSlice converts a map to a slice in go
|
||||
func MapValues[K comparable, V any](m map[K]V) []V {
|
||||
return MapValuesWithExclude(m, map[K]struct{}{})
|
||||
}
|
||||
|
||||
func MapValuesWithExclude[K comparable, V any](m map[K]V, exclude map[K]struct{}) []V {
|
||||
values := make([]V, len(m)-len(exclude))
|
||||
|
||||
i := 0
|
||||
for k, v := range m {
|
||||
if _, excluded := exclude[k]; excluded {
|
||||
continue
|
||||
}
|
||||
|
||||
values[i] = v
|
||||
i++
|
||||
}
|
||||
|
||||
return values
|
||||
}
|
Reference in New Issue
Block a user