kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/util/vnameutil/order.go (about) 1 /* 2 * Copyright 2017 The Kythe Authors. All rights reserved. 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 vnameutil 18 19 import ( 20 "strings" 21 22 spb "kythe.io/kythe/proto/storage_go_proto" 23 ) 24 25 // Compare reports the relative order of two vnames, returning -1 if a < b, 0 26 // if a == b, and 1 if a > b. 27 func Compare(a, b *spb.VName) int { 28 for _, v := range [...]struct{ ap, bp *string }{ 29 {&a.Corpus, &b.Corpus}, 30 {&a.Language, &b.Language}, 31 {&a.Path, &b.Path}, 32 {&a.Root, &b.Root}, 33 {&a.Signature, &b.Signature}, 34 } { 35 if n := strings.Compare(*v.ap, *v.bp); n != 0 { 36 return n 37 } 38 } 39 return 0 40 }