github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/types/kvp.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package types 16 17 // KVP is a simple key value pair 18 type KVP struct { 19 // Key is the key 20 Key LesserValuable 21 22 // Val is the value 23 Val Valuable 24 } 25 26 // KVPSlice is a slice of KVPs that implements sort.Interface 27 type KVPSlice []KVP 28 29 type KVPSort struct { 30 Values []KVP 31 NBF *NomsBinFormat 32 } 33 34 // Len returns the size of the slice 35 func (kvps KVPSort) Len() int { 36 return len(kvps.Values) 37 } 38 39 // Less returns a bool representing whether the key at index i is less than the key at index j 40 func (kvps KVPSort) Less(i, j int) (bool, error) { 41 return kvps.Values[i].Key.Less(kvps.NBF, kvps.Values[j].Key) 42 } 43 44 // Swap swaps the KVP at index i with the KVP at index j 45 func (kvps KVPSort) Swap(i, j int) { 46 kvps.Values[i], kvps.Values[j] = kvps.Values[j], kvps.Values[i] 47 }