github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/ekv/version.go (about)

     1  // Copyright 2020 WHTCORPS INC, 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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package ekv
    15  
    16  import "math"
    17  
    18  // VersionProvider provides increasing IDs.
    19  type VersionProvider interface {
    20  	CurrentVersion() (Version, error)
    21  }
    22  
    23  // Version is the wrapper of KV's version.
    24  type Version struct {
    25  	Ver uint64
    26  }
    27  
    28  var (
    29  	// MaxVersion is the maximum version, notice that it's not a valid version.
    30  	MaxVersion = Version{Ver: math.MaxUint64}
    31  	// MinVersion is the minimum version, it's not a valid version, too.
    32  	MinVersion = Version{Ver: 0}
    33  )
    34  
    35  // NewVersion creates a new Version struct.
    36  func NewVersion(v uint64) Version {
    37  	return Version{
    38  		Ver: v,
    39  	}
    40  }
    41  
    42  // Cmp returns the comparison result of two versions.
    43  // The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
    44  func (v Version) Cmp(another Version) int {
    45  	if v.Ver > another.Ver {
    46  		return 1
    47  	} else if v.Ver < another.Ver {
    48  		return -1
    49  	}
    50  	return 0
    51  }