func NewConnectionInfoIterator(policies []*GameServerAllocationPolicy) *ConnectionInfoIterator {
	priorityToCluster := make(map[int32]map[string][]*GameServerAllocationPolicy)
	for _, policy := range policies {
		priority := policy.Spec.Priority
		clusterName := policy.Spec.ConnectionInfo.ClusterName

		// 1. Add priorities to the map of priority to cluster-priorities map
		clusterPolicy, ok := priorityToCluster[priority]
		if !ok {
			clusterPolicy = make(map[string][]*GameServerAllocationPolicy)
			priorityToCluster[priority] = clusterPolicy
		}

		// 2. Add cluster to the cluster-priorities map
		if _, ok := clusterPolicy[clusterName]; !ok {
			clusterPolicy[clusterName] = []*GameServerAllocationPolicy{policy}
		} else {
			clusterPolicy[clusterName] = append(clusterPolicy[clusterName], policy)
		}
	}

	// 3. Sort priorities
	priorities := make([]int32, 0, len(priorityToCluster))
	for k := range priorityToCluster {
		priorities = append(priorities, k)
	}
	sort.Slice(priorities, func(i, j int) bool { return priorities[i] < priorities[j] })

	// 4. Store initial values for the iterator
	return &ConnectionInfoIterator{priorityToCluster: priorityToCluster, currPriority: 0, orderedPriorities: priorities, clusterBlackList: make(map[string]bool)}
}
// NewConnectionInfoIterator creates an iterator for connection info
NewConnectionInfoIterator creates an iterator for connection info
// NewConnectionInfoIterator creates an iterator for connection info
func NewConnectionInfoIterator(policies []*GameServerAllocationPolicy) *ConnectionInfoIterator {
	priorityToCluster := make(map[int32]map[string][]*GameServerAllocationPolicy)
	for _, policy := range policies {
		priority := policy.Spec.Priority
		clusterName := policy.Spec.ConnectionInfo.ClusterName
		clusterPolicy, ok := priorityToCluster[priority]
		if !ok {
			clusterPolicy = make(map[string][]*GameServerAllocationPolicy)
			priorityToCluster[priority] = clusterPolicy
		}
		if _, ok := clusterPolicy[clusterName]; !ok {
			clusterPolicy[clusterName] = []*GameServerAllocationPolicy{policy}
		} else {
			clusterPolicy[clusterName] = append(clusterPolicy[clusterName], policy)
		}
	}
	priorities := make([]int32, 0, len(priorityToCluster))
	for k := range priorityToCluster {
		priorities = append(priorities, k)
	}
	sort.Slice(priorities, func(i, j int) bool { return priorities[i] < priorities[j] })
	return &ConnectionInfoIterator{priorityToCluster: priorityToCluster, currPriority: 0, orderedPriorities: priorities, clusterBlackList: make(map[string]bool)}
}
func NewConnectionInfoIterator ( policies [ ] * GameServerAllocationPolicy ) * ConnectionInfoIterator { priorityToCluster := make ( map [ int32 ] map [ string ] [ ] * GameServerAllocationPolicy ) for _ , policy := range policies { priority := policy . Spec . Priority clusterName := policy . Spec . ConnectionInfo . ClusterName clusterPolicy , ok := priorityToCluster [ priority ] if ! ok { clusterPolicy = make ( map [ string ] [ ] * GameServerAllocationPolicy ) priorityToCluster [ priority ] = clusterPolicy } if _ , ok := clusterPolicy [ clusterName ] ; ! ok { clusterPolicy [ clusterName ] = [ ] * GameServerAllocationPolicy { policy } } else { clusterPolicy [ clusterName ] = append ( clusterPolicy [ clusterName ] , policy ) } } priorities := make ( [ ] int32 , 0 , len ( priorityToCluster ) ) for k := range priorityToCluster { priorities = append ( priorities , k ) } sort . Slice ( priorities , func ( i , j int ) bool { return priorities [ i ] < priorities [ j ] } ) return & ConnectionInfoIterator { priorityToCluster : priorityToCluster , currPriority : 0 , orderedPriorities : priorities , clusterBlackList : make ( map [ string ] bool ) } }
NewConnectionInfoIterator creates an iterator for connection info
NewConnectionInfoIterator creates an iterator for connection info
// 1. Add priorities to the map of priority to cluster-priorities map // 2. Add cluster to the cluster-priorities map // 3. Sort priorities // 4. Store initial values for the iterator