github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/snowman/bootstrap/interval/interval.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package interval
     5  
     6  import "math"
     7  
     8  type Interval struct {
     9  	LowerBound uint64
    10  	UpperBound uint64
    11  }
    12  
    13  func (i *Interval) Less(other *Interval) bool {
    14  	return i.UpperBound < other.UpperBound
    15  }
    16  
    17  func (i *Interval) Contains(height uint64) bool {
    18  	return i != nil &&
    19  		i.LowerBound <= height &&
    20  		height <= i.UpperBound
    21  }
    22  
    23  // AdjacentToLowerBound returns true if height is 1 less than lowerBound.
    24  func (i *Interval) AdjacentToLowerBound(height uint64) bool {
    25  	return i != nil &&
    26  		height < math.MaxUint64 &&
    27  		height+1 == i.LowerBound
    28  }
    29  
    30  // AdjacentToUpperBound returns true if height is 1 greater than upperBound.
    31  func (i *Interval) AdjacentToUpperBound(height uint64) bool {
    32  	return i != nil &&
    33  		i.UpperBound < math.MaxUint64 &&
    34  		i.UpperBound+1 == height
    35  }