Skip to content

Commit

Permalink
docs: fix and improve package documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn committed Mar 14, 2024
1 parent c2db74c commit 9978438
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">equalizer</h1>
<p align="center">
<a href="https://travis-ci.org/reugn/equalizer"><img src="https://travis-ci.org/reugn/equalizer.svg?branch=master"></a>
<a href="https://github.com/reugn/equalizer/actions/workflows/build.yml"><img src="https://github.com/reugn/equalizer/actions/workflows/build.yml/badge.svg"></a>
<a href="https://pkg.go.dev/github.com/reugn/equalizer"><img src="https://pkg.go.dev/badge/github.com/reugn/equalizer"></a>
<a href="https://goreportcard.com/report/github.com/reugn/equalizer"><img src="https://goreportcard.com/badge/github.com/reugn/equalizer"></a>
<a href="https://codecov.io/gh/reugn/equalizer"><img src="https://codecov.io/gh/reugn/equalizer/branch/master/graph/badge.svg"></a>
Expand Down
16 changes: 8 additions & 8 deletions equalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"sync"
)

// An Equalizer represents a bitmap-based adaptive rate limiter.
// An Equalizer represents an adaptive rate limiter based on a bit array.
//
// The Equalizer uses a round-robin bitmap tape with a moving head to manage
// The Equalizer uses a round-robin bit array with a moving head to manage
// quotas.
// The quota management algorithm is simple and works in the following way.
// To request a permit in a non-blocking manner use the TryAcquire method.
Expand All @@ -23,9 +23,9 @@ import (
// An Equalizer is safe for use by multiple goroutines simultaneously.
type Equalizer struct {
sync.RWMutex
// tape is the underlying bitmap tape
// tape is the underlying bit array
tape *big.Int
// seed is the initial state of the bitmap tape
// seed is the initial state of the bit array tape
seed *big.Int
// mask is the positive bitmask
mask *big.Int
Expand All @@ -38,8 +38,8 @@ type Equalizer struct {
}

// NewEqualizer instantiates and returns a new Equalizer rate limiter, where
// len is the size of the bitmap, reserved is the number of reserved positive
// bits and offset is an instance of the equalizer.Offset strategy.
// size is the length of the bit array, reserved is the number of reserved
// positive bits and offset is an instance of the equalizer.Offset strategy.
func NewEqualizer(size, reserved int, offset Offset) (*Equalizer, error) {
if offset == nil {
return nil, fmt.Errorf("offset is nil")
Expand All @@ -53,7 +53,7 @@ func NewEqualizer(size, reserved int, offset Offset) (*Equalizer, error) {
if reserved > size {
return nil, fmt.Errorf("reserved must not exceed size")
}
// init the seed bitmap tape
// init the seed bit array
var seed big.Int
seed.SetString(strings.Repeat("1", size), 2)

Expand All @@ -62,7 +62,7 @@ func NewEqualizer(size, reserved int, offset Offset) (*Equalizer, error) {
mask.SetString(strings.Repeat("1", reserved), 2)
mask.Lsh(&mask, uint(size-reserved))

// init the bitmap tape
// init the operational bit array tape
var tape big.Int
tape.Set(&seed)

Expand Down
2 changes: 1 addition & 1 deletion internal/async/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Task struct {
stop chan struct{}
}

// New returns a new Task configured to execute periodically at the
// NewTask returns a new Task configured to execute periodically at the
// specified interval.
func NewTask(interval time.Duration) *Task {
return &Task{
Expand Down

0 comments on commit 9978438

Please sign in to comment.