feat: documentation
This commit is contained in:
11
options.go
11
options.go
@@ -2,17 +2,26 @@ package ring
|
||||
|
||||
import "fmt"
|
||||
|
||||
// DefaultGrowthFactor is the default multiplier a [Ring] uses to increase its
|
||||
// capacity. Most implementations use 2.
|
||||
const DefaultGrowthFactor = 2
|
||||
|
||||
// DefaultCapacity is the default starting capacity of a new [Ring]. Sixteen was
|
||||
// chosen as a reasonable default.
|
||||
const DefaultCapacity = 16
|
||||
|
||||
// A config holds all values that modify the behavior of a [Ring].
|
||||
type config struct {
|
||||
capacity uint64
|
||||
growthFactor uint64
|
||||
}
|
||||
|
||||
// An Option can be used with [New] to modify the behavior of a [Ring].
|
||||
type Option func(*config)
|
||||
|
||||
// GrowthFactor modifies the multiplier used to increase (and decrease) the
|
||||
// capacity of a [Ring].
|
||||
// Its value must be greater than 1.
|
||||
func GrowthFactor(value int) Option {
|
||||
if value <= 1 {
|
||||
panic(fmt.Errorf("go-ring: growth factor must be greater than 1, got %d", value))
|
||||
@@ -23,6 +32,8 @@ func GrowthFactor(value int) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Capacity modifies the starting capacity of a [Ring].
|
||||
// Its value must be non-negative.
|
||||
func Capacity(value int) Option {
|
||||
if value < 0 {
|
||||
panic(fmt.Errorf("go-ring: starting capacity must be non-negative, got %d", value))
|
||||
|
||||
Reference in New Issue
Block a user