github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/opt/constraint/key_extension.go (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package constraint
    12  
    13  // KeyExtension is an enumeration used when comparing keys. Key extensions
    14  // specify whether each key is conceptually suffixed with a value that sorts
    15  // before all values (ExtendLow) or with a value that sorts after all values
    16  // (ExtendHigh). This allows span boundaries to be compared with one another.
    17  // See the comment for the Key.Compare method for more details.
    18  type KeyExtension bool
    19  
    20  const (
    21  	// ExtendLow specifies that the key is conceptually suffixed with a value
    22  	// that sorts before all values for purposes of comparison.
    23  	ExtendLow KeyExtension = false
    24  
    25  	// ExtendHigh specifies that the key is conceptually suffixed with a value
    26  	// that sorts after all values for purposes of comparison.
    27  	ExtendHigh KeyExtension = true
    28  )
    29  
    30  // ToCmp converts from a key extension value to a comparison value. ExtendLow
    31  // maps to -1 because it sorts before all other values. ExtendHigh maps to 1
    32  // because it sorts after all other values.
    33  func (e KeyExtension) ToCmp() int {
    34  	// Map ExtendLow into -1 and ExtendHigh into +1.
    35  	if e == ExtendLow {
    36  		return -1
    37  	}
    38  	return 1
    39  }