blockbuffer

package
v1.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2025 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package blockbuffer is a simple heap like structure for keeping a few recent blocks in memory for averaging and analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigIntHeap

type BigIntHeap []*big.Int

BigIntHeap implement the heap interface for big Ints.

func (BigIntHeap) Len

func (h BigIntHeap) Len() int

Len will return the length of our heap

func (BigIntHeap) Less

func (h BigIntHeap) Less(i, j int) bool

Less compares to big.Ints.

func (*BigIntHeap) Pop

func (h *BigIntHeap) Pop() interface{}

Pop will remove the last element in the heap and return it.

func (*BigIntHeap) Push

func (h *BigIntHeap) Push(x interface{})

Push will add an element to the heap.

func (BigIntHeap) Swap

func (h BigIntHeap) Swap(i, j int)

Swap will exchange two elements in our heap.

type BlockBuffer

type BlockBuffer struct {
	// contains filtered or unexported fields
}

The BlockBuffer is a min-heap data structure to keep a set of recent blocks in memory.

func NewBlockBuffer

func NewBlockBuffer(size uint) *BlockBuffer

NewBlockBuffer will return a heap that's constrained to the given size.

func (*BlockBuffer) GetBlock

func (b *BlockBuffer) GetBlock(number uint64) (BufferedBlock, error)

GetBlock will return a block or an error if it doesn't exist.

func (*BlockBuffer) PutBlock

func (b *BlockBuffer) PutBlock(block BufferedBlock) error

PutBlock will push a new block into the heap. If adding that block expand the heap beyond the max size, we'll delete the oldest block (based on number).

type BufferedBlock

type BufferedBlock interface {
	Number() *big.Int
}

BufferedBlock is a way to abstract the block for queueing and sorting. The only thing we need is a block number in order to keep the blocks ordered.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL