...

Source file src/sigs.k8s.io/kustomize/kyaml/sets/stringlist.go

Documentation: sigs.k8s.io/kustomize/kyaml/sets

     1  // Copyright 2019 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package sets
     5  
     6  // StringList is a set, where each element of
     7  // the set is a string slice.
     8  type StringList [][]string
     9  
    10  func (s StringList) Len() int {
    11  	return len(s)
    12  }
    13  
    14  func (s StringList) Insert(val []string) StringList {
    15  	if !s.Has(val) {
    16  		return append(s, val)
    17  	}
    18  	return s
    19  }
    20  
    21  func (s StringList) Has(val []string) bool {
    22  	if len(s) == 0 {
    23  		return false
    24  	}
    25  
    26  	for i := range s {
    27  		if isStringSliceEqual(s[i], val) {
    28  			return true
    29  		}
    30  	}
    31  	return false
    32  }
    33  
    34  func isStringSliceEqual(s []string, t []string) bool {
    35  	if len(s) != len(t) {
    36  		return false
    37  	}
    38  	for i := range s {
    39  		if s[i] != t[i] {
    40  			return false
    41  		}
    42  	}
    43  	return true
    44  }
    45  

View as plain text