Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DynamicConfigLinearIterator ¶
type DynamicConfigLinearIterator[T Integer] struct { // contains filtered or unexported fields }
DynamicConfigLinearIterator is a LinearIterator that can be reconfigured dynamically. It is safe for concurrent use. Every operation checks the values of min, max, and stepCount in dynamic config and refreshes the iterator if they have changed.
func NewDynamicConfigLinearIterator ¶
func NewDynamicConfigLinearIterator[T Integer](min, max func() T, stepCount func() int, logger log.Logger) *DynamicConfigLinearIterator[T]
NewDynamicConfigLinearIterator creates a new DynamicConfigLinearIterator.
func (*DynamicConfigLinearIterator[T]) Next ¶
func (d *DynamicConfigLinearIterator[T]) Next() T
Next returns the next value in the iterator.
func (*DynamicConfigLinearIterator[T]) Previous ¶
func (d *DynamicConfigLinearIterator[T]) Previous() T
Previous returns the previous value in the iterator.
func (*DynamicConfigLinearIterator[T]) Reset ¶
func (d *DynamicConfigLinearIterator[T]) Reset()
Reset resets the iterator to the beginning.
func (*DynamicConfigLinearIterator[T]) Value ¶
func (d *DynamicConfigLinearIterator[T]) Value() T
Value returns the current value in the iterator.
type Integer ¶
type Integer = constraints.Integer
Integer is a type constraint for the Iterator interface to ensure that only integer types are used.
type Iterator ¶
type Iterator[T Integer] interface { // Next returns the next value closer to the max value in the range // If the current value is the max value, Next will return the max value Next() T // Previous returns the previous value closer to the min value in the range // If the current value is the min value, Previous will return the min value Previous() T // Value returns the current value in the range Value() T // Reset resets the Iterator to its initial state Reset() }
Iterator is an interface for iterating through a range between two values. The range is a range of integers from a minimum to a maximum value (inclusive).
type LinearIterator ¶
type LinearIterator[T Integer] struct { // contains filtered or unexported fields }
LinearIterator is an Iterator that steps through a range linearly with a fixed step size. The fixed step size is calculated based on the range and the number of steps provided.
func NewLinearIterator ¶
func NewLinearIterator[T Integer](min, max T, stepCount int) *LinearIterator[T]
NewLinearIterator returns a new LinearIterator. The range is a range of integers from min to max. The stepCount is the number of steps between min and max (both inclusive). After creating the Iterator, the current value will be the middle value of the range. If stepCount is less or equal than 2 or the difference between min and max is less than 1, the Iterator will only have min and max.
- range [0, 10], stepCount 1 -> [0, 10]
- range [10, 10], stepCount 2 -> [10, 10]
If the difference between min and max is less than stepCount, the Iterator will have all the values between min and max.
- range [0, 5], stepCount 10 -> [0, 1, 2, 3, 4, 5]
- range [0, 10], stepCount 11 -> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
func (*LinearIterator[T]) Next ¶
func (s *LinearIterator[T]) Next() T
Next returns the next value in the range.
func (*LinearIterator[T]) Previous ¶
func (s *LinearIterator[T]) Previous() T
Previous returns the previous value in the range.
func (*LinearIterator[T]) Reset ¶
func (s *LinearIterator[T]) Reset()
Reset resets the Iterator to the beginning of the range.
func (*LinearIterator[T]) Value ¶
func (s *LinearIterator[T]) Value() T
Value returns the current value in the range.