github.com/noirx94/tendermintmp@v0.0.1/blockchain/v2/types.go (about)

     1  package v2
     2  
     3  import (
     4  	"github.com/Workiva/go-datastructures/queue"
     5  )
     6  
     7  // Event is the type that can be added to the priority queue.
     8  type Event queue.Item
     9  
    10  type priority interface {
    11  	Compare(other queue.Item) int
    12  	Priority() int
    13  }
    14  
    15  type priorityLow struct{}
    16  type priorityNormal struct{}
    17  type priorityHigh struct{}
    18  
    19  func (p priorityLow) Priority() int {
    20  	return 1
    21  }
    22  
    23  func (p priorityNormal) Priority() int {
    24  	return 2
    25  }
    26  
    27  func (p priorityHigh) Priority() int {
    28  	return 3
    29  }
    30  
    31  func (p priorityLow) Compare(other queue.Item) int {
    32  	op := other.(priority)
    33  	if p.Priority() > op.Priority() {
    34  		return 1
    35  	} else if p.Priority() == op.Priority() {
    36  		return 0
    37  	}
    38  	return -1
    39  }
    40  
    41  func (p priorityNormal) Compare(other queue.Item) int {
    42  	op := other.(priority)
    43  	if p.Priority() > op.Priority() {
    44  		return 1
    45  	} else if p.Priority() == op.Priority() {
    46  		return 0
    47  	}
    48  	return -1
    49  }
    50  
    51  func (p priorityHigh) Compare(other queue.Item) int {
    52  	op := other.(priority)
    53  	if p.Priority() > op.Priority() {
    54  		return 1
    55  	} else if p.Priority() == op.Priority() {
    56  		return 0
    57  	}
    58  	return -1
    59  }
    60  
    61  type noOpEvent struct {
    62  	priorityLow
    63  }
    64  
    65  var noOp = noOpEvent{}