github.com/koko1123/flow-go-1@v0.29.6/module/mempool/herocache/backdata/heropool/poolIndex.go (about)

     1  package heropool
     2  
     3  // poolIndex represents a slice-based linked list pointer. Instead of pointing
     4  // to a memory address, this pointer points to a slice index.
     5  //
     6  // Note: an "undefined" (i.e., nil) notion for this poolIndex corresponds to the
     7  // value of uint32(0). Hence, legit "index" poolEntities start from uint32(1).
     8  // poolIndex also furnished with methods to convert a "poolIndex" value to
     9  // a slice index, and vice versa.
    10  type poolIndex struct {
    11  	index uint32
    12  }
    13  
    14  // isUndefined returns true if this poolIndex is set to zero. An undefined
    15  // poolIndex is equivalent to a nil address-based one.
    16  func (p poolIndex) isUndefined() bool {
    17  	return p.index == uint32(0)
    18  }
    19  
    20  // setUndefined sets poolIndex to its undefined (i.e., nil equivalent) value.
    21  func (p *poolIndex) setUndefined() {
    22  	p.index = uint32(0)
    23  }
    24  
    25  // getSliceIndex returns the slice-index equivalent of the poolIndex.
    26  func (p poolIndex) getSliceIndex() EIndex {
    27  	return EIndex(p.index) - 1
    28  }
    29  
    30  // setPoolIndex converts the input slice-based index into a pool index and
    31  // sets the underlying poolIndex.
    32  func (p *poolIndex) setPoolIndex(sliceIndex EIndex) {
    33  	p.index = uint32(sliceIndex + 1)
    34  }