github.com/cilium/statedb@v0.3.2/index/set.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package index 5 6 import "github.com/cilium/statedb/part" 7 8 // Set creates a KeySet from a part.Set. 9 func Set[T any](s part.Set[T]) KeySet { 10 toBytes := s.ToBytesFunc() 11 switch s.Len() { 12 case 0: 13 return NewKeySet() 14 case 1: 15 for v := range s.All() { 16 return NewKeySet(toBytes(v)) 17 } 18 panic("BUG: Set.Len() == 1, but ranging returned nothing") 19 default: 20 keys := make([]Key, 0, s.Len()) 21 for v := range s.All() { 22 keys = append(keys, toBytes(v)) 23 } 24 return NewKeySet(keys...) 25 } 26 }