mempool

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item interface {
	ID() ids.ID
	Payer() string
	Expiry() int64
	UnitPrice() uint64
}

type Mempool

type Mempool[T Item] struct {
	// contains filtered or unexported fields
}

func New

func New[T Item](
	tracer trace.Tracer,
	maxSize int,
	maxPayerSize int,
	exemptPayers [][]byte,
) *Mempool[T]

New creates a new Mempool. [maxSize] must be > 0 or else the implementation may panic.

func (*Mempool[T]) Add

func (th *Mempool[T]) Add(ctx context.Context, items []T)

Add pushes all new items from [items] to th. Does not add a item if the item payer is not exempt and their items in the mempool exceed th.maxPayerSize. If the size of th exceeds th.maxSize, Add pops the lowest value item from th.pm.

func (*Mempool[T]) Build

func (th *Mempool[T]) Build(
	ctx context.Context,
	f func(context.Context, T) (cont bool, restore bool, removeAcct bool, err error),
) error

func (*Mempool[T]) Has

func (th *Mempool[T]) Has(ctx context.Context, itemID ids.ID) bool

Has returns if the pm of [th] contains [itemID]

func (*Mempool[T]) Len

func (th *Mempool[T]) Len(ctx context.Context) int

Len returns the number of items in th.

func (*Mempool[T]) PeekMax

func (th *Mempool[T]) PeekMax(ctx context.Context) (T, bool)

PeekMax returns the highest valued item in th.pm. Assumes there is non-zero items in Mempool

func (*Mempool[T]) PeekMin

func (th *Mempool[T]) PeekMin(ctx context.Context) (T, bool)

PeekMin returns the lowest valued item in th.pm. Assumes there is non-zero items in Mempool

func (*Mempool[T]) PopMax

func (th *Mempool[T]) PopMax(ctx context.Context) (T, bool)

PopMax removes and returns the highest valued item in th.pm. Assumes there is non-zero items in Mempool

func (*Mempool[T]) PopMin

func (th *Mempool[T]) PopMin(ctx context.Context) (T, bool)

PopMin removes and returns the lowest valued item in th.pm. Assumes there is non-zero items in Mempool

func (*Mempool[T]) Remove

func (th *Mempool[T]) Remove(ctx context.Context, items []T)

Remove removes [items] from th.

func (*Mempool[T]) RemoveAccount

func (th *Mempool[T]) RemoveAccount(ctx context.Context, sender string)

RemoveAccount removes all items by [sender] from th.

func (*Mempool[T]) SetMinTimestamp

func (th *Mempool[T]) SetMinTimestamp(ctx context.Context, t int64) []T

SetMinTimestamp removes all items with a lower expiry than [t] from th. SetMinTimestamp returns the list of removed items.

type SortedMempool

type SortedMempool[T Item] struct {
	// GetValue informs heaps how to get the an entry's value for ordering.
	GetValue func(item T) uint64
	// contains filtered or unexported fields
}

SortedMempool contains a max-heap and min-heap. The order within each heap is determined by using GetValue.

func NewSortedMempool

func NewSortedMempool[T Item](items int, f func(item T) uint64) *SortedMempool[T]

NewSortedMempool returns an instance of SortedMempool with minHeap and maxHeap containing [items] and prioritized with [f]

func (*SortedMempool[T]) Add

func (sm *SortedMempool[T]) Add(item T)

Add pushes [item] to sm.

func (*SortedMempool[T]) Has

func (sm *SortedMempool[T]) Has(item ids.ID) bool

Has returns if [item] is in sm.

func (*SortedMempool[T]) Len

func (sm *SortedMempool[T]) Len() int

Len returns the number of elements in sm.

func (*SortedMempool[T]) PeekMax

func (sm *SortedMempool[T]) PeekMax() (T, bool)

PopMin returms the maximum value in sm.

func (*SortedMempool[T]) PeekMin

func (sm *SortedMempool[T]) PeekMin() (T, bool)

PeekMin returns the minimum value in sm.

func (*SortedMempool[T]) PopMax

func (sm *SortedMempool[T]) PopMax() (T, bool)

PopMin removes the maximum value in sm.

func (*SortedMempool[T]) PopMin

func (sm *SortedMempool[T]) PopMin() (T, bool)

PopMin removes the minimum value in sm.

func (*SortedMempool[T]) Remove

func (sm *SortedMempool[T]) Remove(id ids.ID)

Remove removes [id] from sm. If the id does not exist, Remove returns.

func (*SortedMempool[T]) SetMinVal

func (sm *SortedMempool[T]) SetMinVal(val uint64) []T

SetMinVal removes all elements in sm with a value less than [val]. Returns the list of removed elements. TDOD: add lock to prevent concurrent access

Jump to

Keyboard shortcuts

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