...

Source file src/k8s.io/kubernetes/pkg/apis/flowcontrol/util/helpers.go

Documentation: k8s.io/kubernetes/pkg/apis/flowcontrol/util

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package util
    18  
    19  import (
    20  	"sort"
    21  
    22  	"k8s.io/kubernetes/pkg/apis/flowcontrol"
    23  )
    24  
    25  var _ sort.Interface = FlowSchemaSequence{}
    26  
    27  // FlowSchemaSequence holds sorted set of pointers to FlowSchema objects.
    28  // FlowSchemaSequence implements `sort.Interface`
    29  type FlowSchemaSequence []*flowcontrol.FlowSchema
    30  
    31  func (s FlowSchemaSequence) Len() int {
    32  	return len(s)
    33  }
    34  
    35  func (s FlowSchemaSequence) Less(i, j int) bool {
    36  	// the flow-schema w/ lower matching-precedence is prior
    37  	if ip, jp := s[i].Spec.MatchingPrecedence, s[j].Spec.MatchingPrecedence; ip != jp {
    38  		return ip < jp
    39  	}
    40  	// sort alphabetically
    41  	return s[i].Name < s[j].Name
    42  }
    43  
    44  func (s FlowSchemaSequence) Swap(i, j int) {
    45  	s[i], s[j] = s[j], s[i]
    46  }
    47  

View as plain text