github.com/koko1123/flow-go-1@v0.29.6/module/mempool/stdmap/options.go (about) 1 // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED 2 3 package stdmap 4 5 import ( 6 "github.com/koko1123/flow-go-1/module/mempool" 7 ) 8 9 // OptionFunc is a function that can be provided to the backend on creation in 10 // order to set a certain custom option. 11 type OptionFunc func(*Backend) 12 13 // WithLimit can be provided to the backend on creation in order to set a point 14 // where it's time to check for ejection conditions. The actual size may continue 15 // to rise by the threshold for batch ejection (currently 128) 16 func WithLimit(limit uint) OptionFunc { 17 return func(be *Backend) { 18 be.guaranteedCapacity = limit 19 } 20 } 21 22 // WithEject can be provided to the backend on creation in order to set a custom 23 // eject function to pick the entity to be evicted upon overflow, as well as 24 // hooking into it for additional cleanup work. 25 func WithEject(eject EjectFunc) OptionFunc { 26 return func(be *Backend) { 27 be.eject = eject 28 be.batchEject = nil 29 } 30 } 31 32 // WithBackData sets the underlying backdata of the backend. 33 // BackData represents the underlying data structure that is utilized by mempool.Backend, as the 34 // core structure of maintaining data on memory-pools. 35 func WithBackData(backdata mempool.BackData) OptionFunc { 36 return func(be *Backend) { 37 be.backData = backdata 38 } 39 }