Skip to content

Commit 20c03c4

Browse files
committed
Address english syntax and grammar based on vale's linter
1 parent 4a776fa commit 20c03c4

9 files changed

+136
-130
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ _cgo_export.*
2020
_testmain.go
2121

2222
*.exe
23+
24+
styles/

Diff for: .vale.ini

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
StylesPath = styles
2+
3+
MinAlertLevel = suggestion
4+
Vocab = Lane
5+
6+
Packages = Google, proselint, write-good
7+
8+
[*]
9+
BasedOnStyles = Vale, Google, proselint, write-good

Diff for: README.md

+34-35
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Go Report Card](https://goreportcard.com/badge/github.com/oleiade/lane)](https://goreportcard.com/report/github.com/oleiade/lane)
77
![Go Version](https://img.shields.io/github/go-mod/go-version/oleiade/lane)
88

9-
The Lane package provides implementations of generic `Queue`, `PriorityQueue`, `Stack`, and `Deque` data structures. It was designed with simplicity, performance, and concurrent usage in mind.
9+
The Lane package provides implementations of generic `Queue`, `PriorityQueue`, `Stack`, and `Deque` data structures. Its design focuses on simplicity, performance, and concurrent usage.
1010

1111
<!-- toc -->
1212

@@ -15,14 +15,14 @@ The Lane package provides implementations of generic `Queue`, `PriorityQueue`, `
1515
- [Using `v2` releases](#using-v2-releases)
1616
- [Using `v1` releases](#using-v1-releases)
1717
- [Usage/Examples](#usageexamples)
18-
- [Priority Queue](#priority-queue)
18+
- [Priority queue](#priority-queue)
1919
- [Example](#example)
2020
- [Deque](#deque)
21-
- [Deque Example](#deque-example)
21+
- [Deque example](#deque-example)
2222
- [Queue](#queue)
23-
- [Queue Example](#queue-example)
23+
- [Queue example](#queue-example)
2424
- [Stack](#stack)
25-
- [Stack Example](#stack-example)
25+
- [Stack example](#stack-example)
2626
- [Performance](#performance)
2727
- [Documentation](#documentation)
2828
- [License](#license)
@@ -31,7 +31,7 @@ The Lane package provides implementations of generic `Queue`, `PriorityQueue`, `
3131

3232
Using this package requires a working Go environment. [See the install instructions for Go](http://golang.org/doc/install.html).
3333

34-
Go Modules are required when using this package. [See the go blog guide on using Go Modules](https://blog.golang.org/using-go-modules).
34+
This package requires a modern version of Go supporting modules: [see the go blog guide on using Go Modules](https://blog.golang.org/using-go-modules).
3535

3636
### Using `v2` releases
3737

@@ -63,32 +63,31 @@ import (
6363

6464
## Usage/Examples
6565

66-
### Priority Queue
66+
### Priority queue
6767

68-
`PriorityQueue` is a _heap priority queue_ data structure implementation. It can be either maximum (descending) or minimum (ascending) oriented (ordered). Every operation on a `PriorityQueue` are synchronized and goroutine-safe. It performs `Push` and `Pop` operations in `O(log N)` time.
68+
`PriorityQueue` implements a _heap priority queue_ data structure. It can be either max (descending) or min (ascending) ordered. Every operation on a `PriorityQueue` is goroutine-safe. It performs `Push` and `Pop` operations in *O(log N)* time.
6969

7070
#### Example
7171

7272
```go
73-
// Let's create a new max ordered priority queue
74-
priorityQueue := lane.NewMaxPriorityQueue[string, int]()
73+
// Create a new max ordered priority queue
74+
priorityQueue := NewMaxPriorityQueue[string, int]()
7575

7676
// And push some prioritized content into it
7777
priorityQueue.Push("easy as", 3)
7878
priorityQueue.Push("123", 2)
7979
priorityQueue.Push("do re mi", 4)
8080
priorityQueue.Push("abc", 1)
8181

82-
// Now let's take a look at the min element in
82+
// Take a look at the min element in
8383
// the priority queue
8484
headValue, headPriority, ok := priorityQueue.Head()
8585
if ok {
8686
fmt.Println(headValue) // "abc"
8787
fmt.Println(headPriority) // 1
8888
}
8989

90-
// Okay the song order seems to be preserved, let's
91-
// roll
90+
// The operations seem to preserve the song order
9291
jacksonFive := make([]string, priorityQueue.Size())
9392

9493
for i := 0; i < len(jacksonFive); i++ {
@@ -101,15 +100,15 @@ fmt.Println(strings.Join(jacksonFive, " "))
101100

102101
### Deque
103102

104-
Deque is a _head-tail linked list data_ structure implementation. It is built upon a doubly-linked list container, and every operation on a `Deque` are performed in `O(1)` time complexity. Every operation on a `Deque` is synchronized and goroutine-safe.
103+
Deque implements a _head-tail linked list data_ structure. Built upon a doubly linked list container, every operation performed on a `Deque` happen in *O(1)* time complexity. Every operation on a `Deque` are goroutine-safe.
105104

106-
Deques can optionally be instantiated with a limited capacity using the dedicated `NewBoundDeque` constructor, whereby the return value of the `Append` and `Prepend` return false if the Deque was full and the item was not added.
105+
Users have the option to instantiate Deques with a limited capacity using the dedicated `NewBoundDeque` constructor. When a bound Deque is full, the `Append` and `Prepend` operations fail.
107106

108-
#### Deque Example
107+
#### Deque example
109108

110109
```go
111-
// Let's create a new deque data structure
112-
deque := lane.NewDeque[string]()
110+
// Create a new Deque data structure
111+
deque := NewDeque[string]()
113112

114113
// And push some content into it using the Append
115114
// and Prepend methods
@@ -118,8 +117,8 @@ deque.Prepend("123")
118117
deque.Append("do re mi")
119118
deque.Prepend("abc")
120119

121-
// Now let's take a look at what are the first and
122-
// last element stored in the Deque
120+
// Take a look at what the first and
121+
// last element stored in the Deque are.
123122
firstValue, ok := deque.First()
124123
if ok {
125124
fmt.Println(firstValue) // "abc"
@@ -130,7 +129,7 @@ if ok {
130129
fmt.Println(lastValue) // 1
131130
}
132131

133-
// Okay now let's play with the Pop and Shift
132+
// Use the `Pop` and `Shift`
134133
// methods to bring the song words together
135134
jacksonFive := make([]string, deque.Size())
136135

@@ -147,23 +146,22 @@ fmt.Println(strings.Join(jacksonFive, " "))
147146

148147
### Queue
149148

150-
`Queue` is a **FIFO** (_First In First Out_) data structure implementation. It is built upon a `Deque` container and focuses its API on core functionalities: `Enqueue`, `Dequeue`, `Head`. Every operation's time complexity is O(1). Every operation on a `Queue` is synchronized and goroutine-safe.
149+
`Queue` is a **FIFO** (_First In First Out_) data structure implementation. Built upon a `Deque` container, it focuses its API on the following core functionalities: `Enqueue`, `Dequeue`, `Head`. Every operation on a Queue has a time complexity of *O(1)*. Every operation on a `Queue` is goroutine-safe.
151150

152-
#### Queue Example
151+
#### Queue example
153152

154153
```go
155-
// Create a new queue and pretend we're handling starbucks
156-
// clients
157-
queue := lane.NewQueue[string]()
154+
// Create a new queue and pretend to handle Starbucks clients
155+
queue := NewQueue[string]()
158156

159-
// Let's add the incoming clients to the queue
157+
// Add the incoming clients to the queue
160158
queue.Enqueue("grumpyClient")
161159
queue.Enqueue("happyClient")
162160
queue.Enqueue("ecstaticClient")
163161

164162
fmt.Println(queue.Head()) // grumpyClient
165163

166-
// Let's handle the clients asynchronously
164+
// Handle the clients asynchronously
167165
for {
168166
client, ok := queue.Dequeue()
169167
if !ok {
@@ -176,21 +174,22 @@ for {
176174

177175
### Stack
178176

179-
`Stack` is a **LIFO** ( _Last in first out_ ) data structure implementation. It is built upon a `Deque` container and focuses its API on core functionalities: `Push`, `Pop`, `Head`. Every operation time complexity is O(1). Every operation on a `Stack` is synchronized and goroutine-safe.
177+
`Stack` implements a **Last In First Out** data structure. Built upon a `Deque` container, its API focuses on the following core functionalities: `Push`, `Pop`, `Head`. Every operation on a Stack has a time complexity of *O(1)*. Every operation on a `Stack` is goroutine-safe.
180178

181-
#### Stack Example
179+
#### Stack example
182180

183181
```go
184-
stack := lane.NewStack[string]()
182+
// Create a new stack and put some plates over it
183+
stack := NewStack[string]()
185184

186-
// Let's put some plates on the stack
185+
// Put some plates on the stack
187186
stack.Push("redPlate")
188187
stack.Push("bluePlate")
189188
stack.Push("greenPlate")
190189

191190
fmt.Println(stack.Head()) // greenPlate
192191

193-
// What's on top of the stack?
192+
// Check the top of the stack
194193
value, ok := stack.Pop()
195194
if ok {
196195
fmt.Println(value) // greenPlate
@@ -203,13 +202,13 @@ if ok {
203202
fmt.Println(value) // yellowPlate
204203
}
205204

206-
// What's on top of the stack?
205+
// Check the top of the stack
207206
value, ok = stack.Pop()
208207
if ok {
209208
fmt.Println(value) // bluePlate
210209
}
211210

212-
// What's on top of the stack?
211+
// Check the top of the stack
213212
value, ok = stack.Pop()
214213
if ok {
215214
fmt.Println(value) // redPlate

Diff for: deque.go

+43-43
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ type Dequer[T any] interface {
99
Deque[T] | BoundDeque[T]
1010
}
1111

12-
// Deque is a head-tail linked list data structure implementation.
12+
// Deque implements a head-tail linked list data structure.
1313
//
14-
// The Deque's implementation is built upon a doubly linked list
15-
// container, so that every operations' time complexity is O(1) (N.B:
16-
// linked-list are not CPU-cache friendly).
17-
// Every operation on a Deque are goroutine-safe and ready
14+
// Under the hood, the Deque's implementation is built upon a doubly linked list
15+
// container, so that every operation's time complexity is *O(1)*.
16+
// Every operation on a Deque is goroutine-safe and ready.
17+
//
18+
// Note that linked-list are not CPU-cache friendly).
1819
// for concurrent usage.
1920
type Deque[T any] struct {
2021
sync.RWMutex
2122

22-
// container is the underlying storage container
23-
// of deque's elements.
23+
// The underlying storage container.
2424
container *List[T]
2525
}
2626

@@ -37,23 +37,23 @@ func NewDeque[T any](items ...T) *Deque[T] {
3737
}
3838
}
3939

40-
// Append inserts item at the back of the Deque in a O(1) time complexity.
40+
// Append inserts item at the back of the Deque in an *O(1)* time complexity.
4141
func (d *Deque[T]) Append(item T) {
4242
d.Lock()
4343
defer d.Unlock()
4444

4545
d.container.PushBack(item)
4646
}
4747

48-
// Prepend inserts item at the Deque's front in a O(1) time complexity.
48+
// Prepend inserts item at the Deque's front in an *O(1)* time complexity.
4949
func (d *Deque[T]) Prepend(item T) {
5050
d.Lock()
5151
defer d.Unlock()
5252

5353
d.container.PushFront(item)
5454
}
5555

56-
// Pop removes and returns the back element of the Deque in O(1) time complexity.
56+
// Pop removes and returns the back element of the Deque in an *O(1)* time complexity.
5757
func (d *Deque[T]) Pop() (item T, ok bool) {
5858
d.Lock()
5959
defer d.Unlock()
@@ -67,7 +67,7 @@ func (d *Deque[T]) Pop() (item T, ok bool) {
6767
return
6868
}
6969

70-
// Shift removes and returns the front element of the Deque in O(1) time complexity.
70+
// Shift removes and returns the front element of the Deque in *O(1)* time complexity.
7171
func (d *Deque[T]) Shift() (item T, ok bool) {
7272
d.Lock()
7373
defer d.Unlock()
@@ -81,7 +81,7 @@ func (d *Deque[T]) Shift() (item T, ok bool) {
8181
return
8282
}
8383

84-
// First returns the first value stored in the Deque in O(1) time complexity.
84+
// First returns the first value stored in the Deque in *O(1)* time complexity.
8585
func (d *Deque[T]) First() (item T, ok bool) {
8686
d.RLock()
8787
defer d.RUnlock()
@@ -95,7 +95,7 @@ func (d *Deque[T]) First() (item T, ok bool) {
9595
return
9696
}
9797

98-
// Last returns the last value stored in the Deque in O(1) time complexity.
98+
// Last returns the last value stored in the Deque in *O(1)* time complexity.
9999
func (d *Deque[T]) Last() (item T, ok bool) {
100100
d.RLock()
101101
defer d.RUnlock()
@@ -116,32 +116,32 @@ func (d *Deque[T]) Size() uint {
116116
return d.container.Len()
117117
}
118118

119-
// Empty checks if the deque is empty.
119+
// Empty checks if the Deque is empty.
120120
func (d *Deque[T]) Empty() bool {
121121
d.RLock()
122122
defer d.RUnlock()
123123

124124
return d.container.Len() == 0
125125
}
126126

127-
// Capaciter is an interface type providing operations
128-
// related to capacity management.
129-
type Capaciter interface {
127+
// Capacitor defines operations related to capacity management.
128+
type Capacitor interface {
130129
// Capacity returns the current capacity of the underlying type implementation.
131130
Capacity() int
132131

133132
// IsFull returns whether the implementing type instance is full.
134133
IsFull() bool
135134
}
136135

137-
// BoundDeque is a head-tail linked list data structure implementation
138-
// with a user-defined capacity: any operation leading to the size
139-
// of the container to overflow its capacity will fail.
136+
// BoundDeque implements a head-tail linked list data structure
137+
// with a user-defined capacity. Once full, `Append` and `Prepend`
138+
// operations on a BoundedDeque fail.
139+
//
140+
// Under the hood, BoundDeque's implementation relies upon a doubly linked list
141+
// container. Thus, every operation on a BoundedDeque has a time complexity of *O(1)*.
142+
// Every operation on a BoundDeque is goroutine-safe.
140143
//
141-
// The BoundDeque's implementation is built upon a doubly linked list
142-
// container, so that every operations' time complexity is O(1) (N.B:
143-
// linked-list are not CPU-cache friendly).
144-
// Every operation on a BoundDeque are goroutine-safe and ready
144+
// Note that linked-list are not CPU-cache friendly).
145145
// for concurrent usage.
146146
type BoundDeque[T any] struct {
147147
Deque[T]
@@ -159,42 +159,42 @@ func NewBoundDeque[T any](capacity uint, values ...T) *BoundDeque[T] {
159159
}
160160
}
161161

162-
// Capacity returns the BoundDeque's capacity.
163-
func (bd *BoundDeque[T]) Capacity() uint {
164-
return bd.capacity
162+
// Capacity returns BoundDeque's capacity.
163+
func (d *BoundDeque[T]) Capacity() uint {
164+
return d.capacity
165165
}
166166

167167
// Full checks if the BoundDeque is full.
168-
func (bd *BoundDeque[T]) Full() bool {
169-
return bd.container.Len() >= bd.capacity
168+
func (d *BoundDeque[T]) Full() bool {
169+
return d.container.Len() >= d.capacity
170170
}
171171

172-
// Append inserts item at the back of the BoundDeque in a O(1) time complexity.
173-
// If the BoundDeque's capacity disallows the insertion, Append returns false.
174-
func (bd *BoundDeque[T]) Append(item T) bool {
175-
bd.Lock()
176-
defer bd.Unlock()
172+
// Append inserts an item at the back of the BoundDeque in an *O(1)* time complexity.
173+
// If BoundDeque's capacity disallows the insertion, Append returns false.
174+
func (d *BoundDeque[T]) Append(item T) bool {
175+
d.Lock()
176+
defer d.Unlock()
177177

178-
if bd.Full() {
178+
if d.Full() {
179179
return false
180180
}
181181

182-
bd.container.PushBack(item)
182+
d.container.PushBack(item)
183183

184184
return true
185185
}
186186

187-
// Prepend inserts item at the BoundDeque's front in a O(1) time complexity.
188-
// If the BoundDeque's capacity disallows the insertion, Prepend returns false.
189-
func (bd *BoundDeque[T]) Prepend(item T) bool {
190-
bd.Lock()
191-
defer bd.Unlock()
187+
// Prepend inserts item at the BoundDeque's front in an *O(1)* time complexity.
188+
// If BoundDeque's capacity disallows the insertion, Prepend returns false.
189+
func (d *BoundDeque[T]) Prepend(item T) bool {
190+
d.Lock()
191+
defer d.Unlock()
192192

193-
if bd.Full() {
193+
if d.Full() {
194194
return false
195195
}
196196

197-
bd.container.PushFront(item)
197+
d.container.PushFront(item)
198198

199199
return true
200200
}

0 commit comments

Comments
 (0)