go-ethereum/common/set/slice.go
Evgeny Danilenko 22fa4033e8
Event based pprof (#732)
* feature

* Save pprof to /tmp

---------

Co-authored-by: Jerry <jerrycgh@gmail.com>
2023-02-08 13:41:09 -08:00

28 lines
402 B
Go

package set
func New[T comparable](slice []T) map[T]struct{} {
m := make(map[T]struct{}, len(slice))
for _, el := range slice {
m[el] = struct{}{}
}
return m
}
func ToSlice[T comparable](m map[T]struct{}) []T {
slice := make([]T, len(m))
var i int
for k := range m {
slice[i] = k
i++
}
return slice
}
func Deduplicate[T comparable](slice []T) []T {
return ToSlice(New(slice))
}