func (s *Set) Len() int {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	return len(s.bundles)
}
Len returns the number of bundles in the set.
package x509bundle
import (
	"sort"
	"sync"
	"github.com/spiffe/go-spiffe/v2/spiffeid"
)
type Set struct {
	mtx     sync.RWMutex
	bundles map[spiffeid.TrustDomain]*Bundle
}
func NewSet(bundles ...*Bundle) *Set {
	bundlesMap := make(map[spiffeid.TrustDomain]*Bundle)
	for _, b := range bundles {
		if b != nil {
			bundlesMap[b.trustDomain] = b
		}
	}
	return &Set{
		bundles: bundlesMap,
	}
}
func (s *Set) Add(bundle *Bundle) {
	s.mtx.Lock()
	defer s.mtx.Unlock()
	if bundle != nil {
		s.bundles[bundle.trustDomain] = bundle
	}
}
func (s *Set) Remove(trustDomain spiffeid.TrustDomain) {
	s.mtx.Lock()
	defer s.mtx.Unlock()
	delete(s.bundles, trustDomain)
}
func (s *Set) Has(trustDomain spiffeid.TrustDomain) bool {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	_, ok := s.bundles[trustDomain]
	return ok
}
func (s *Set) Get(trustDomain spiffeid.TrustDomain) (*Bundle, bool) {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	bundle, ok := s.bundles[trustDomain]
	return bundle, ok
}
func (s *Set) Bundles() []*Bundle {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	out := make([]*Bundle, 0, len(s.bundles))
	for _, bundle := range s.bundles {
		out = append(out, bundle)
	}
	sort.Slice(out, func(a, b int) bool {
		return out[a].TrustDomain().Compare(out[b].TrustDomain()) < 0
	})
	return out
}