feat: documentation

This commit is contained in:
2026-04-05 15:01:17 -04:00
parent 895daf6002
commit 2cf1847dca
4 changed files with 266 additions and 9 deletions

View File

@@ -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))