Skip to content

Commit 5f974fd

Browse files
committed
bump to v2.2.0
- added overlapped ring bugger implementation via `NewOverlappedRingBuffer()`
1 parent 0fe67fa commit 5f974fd

File tree

2 files changed

+62
-49
lines changed

2 files changed

+62
-49
lines changed

README.md

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Go](https://github.com/hedzr/go-ringbuf/workflows/Go/badge.svg)
44
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/hedzr/go-ringbuf.svg?label=release)](https://github.com/hedzr/go-ringbuf/releases)
5-
[![](https://img.shields.io/badge/go-dev-green)](https://pkg.go.dev/github.com/hedzr/go-ringbuf)
5+
[![go.dev](https://img.shields.io/badge/go-dev-green)](https://pkg.go.dev/github.com/hedzr/go-ringbuf)
66
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/hedzr/go-ringbuf)
77
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fhedzr%2Fgo-ringbuf.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhedzr%2Fgo-ringbuf?ref=badge_shield)
88
[![Go Report Card](https://goreportcard.com/badge/github.com/hedzr/go-ringbuf)](https://goreportcard.com/report/github.com/hedzr/go-ringbuf)
@@ -14,14 +14,19 @@
1414

1515
`go-ringbuf` provides a high-performance, lock-free circular queue (ring buffer) implementation in golang.
1616

17-
MPMC (multiple-producers and multiple consumers) enabled.
17+
MPMC (multiple producers and multiple consumers) enabled.
1818

1919
## History
2020

21+
### v2.2.0
22+
23+
- added new impl to support overlapped ringbuf
24+
- security updates
25+
2126
### v2.1.0
2227

2328
- remove extras deps
24-
- use 'log/slog' instead 'hedzr/log', 'errors' instead 'hedzr/errors.v3'
29+
- replaced 'hedzr/log' with 'log/slog', 'hedzr/errors.v3' with 'errors'
2530
- remove WithLogger()
2631

2732
### v2.0.+
@@ -34,7 +39,7 @@ generic version for MPMC Ring Buffer.
3439

3540
- rewritten with go generics
3641

37-
### v1.0.+
42+
### v1.0.+ [archived]
3843

3944
security updates
4045

@@ -54,63 +59,60 @@ Next release (v2) will move to go 1.18+ with generic enabled.
5459
- we have no more 3rd-party deps.
5560
- we assumed a free license under MIT (unified).
5661

57-
5862
## Getting Start
5963

6064
```bash
6165
go get -v github.com/hedzr/go-ringbuf/v2
6266
```
6367

64-
6568
### Samples
6669

6770
```go
6871
package main
6972

7073
import (
71-
"fmt"
72-
"github.com/hedzr/go-ringbuf/v2"
73-
"log"
74+
"fmt"
75+
"log"
76+
77+
"github.com/hedzr/go-ringbuf/v2"
7478
)
7579

7680
func main() {
77-
testIntRB()
78-
testStringRB()
81+
testIntRB()
82+
testStringRB()
7983
}
8084

8185
func testStringRB() {
82-
var err error
83-
var rb = ringbuf.New[string](80)
84-
err = rb.Enqueue("abcde")
85-
errChk(err)
86-
87-
var item string
88-
item, err = rb.Dequeue()
89-
errChk(err)
90-
fmt.Printf("dequeue ok: %v\n", item)
86+
var err error
87+
var rb = ringbuf.New[string](80)
88+
err = rb.Enqueue("abcde")
89+
errChk(err)
90+
91+
var item string
92+
item, err = rb.Dequeue()
93+
errChk(err)
94+
fmt.Printf("dequeue ok: %v\n", item)
9195
}
9296

9397
func testIntRB() {
94-
var err error
95-
var rb = ringbuf.New[int](80)
96-
err = rb.Enqueue(3)
97-
errChk(err)
98-
99-
var item int
100-
item, err = rb.Dequeue()
101-
errChk(err)
102-
fmt.Printf("dequeue ok: %v\n", item)
98+
var err error
99+
var rb = ringbuf.New[int](80)
100+
err = rb.Enqueue(3)
101+
errChk(err)
102+
103+
var item int
104+
item, err = rb.Dequeue()
105+
errChk(err)
106+
fmt.Printf("dequeue ok: %v\n", item)
103107
}
104108

105109
func errChk(err error) {
106-
if err != nil {
107-
log.Fatal(err)
108-
}
110+
if err != nil {
111+
log.Fatal(err)
112+
}
109113
}
110114
```
111115

112-
113-
114116
### Using Ring-Buffer as a fixed resource pool
115117

116118
The following codes is for v1, needed for rewriting
@@ -124,16 +126,16 @@ func initFunc() (err error) {
124126
const maxSize = 16
125127

126128
if rb = fast.New(uint32(maxSize)); rb == nil {
127-
err = errors.New("cannot create fast.RingBuffer")
128-
return
129-
}
129+
err = errors.New("cannot create fast.RingBuffer")
130+
return
131+
}
130132

131133
// CapReal() will be available since v0.8.8, or replace it with Cap() - 1
132-
for i := uint32(0); i < rb.CapReal(); i++ {
133-
if err = rb.Enqueue(newRes()); err != nil {
134-
return
135-
}
136-
}
134+
for i := uint32(0); i < rb.CapReal(); i++ {
135+
if err = rb.Enqueue(newRes()); err != nil {
136+
return
137+
}
138+
}
137139
}
138140

139141
func loopFor() {
@@ -149,18 +151,29 @@ func loopFor() {
149151
}
150152
```
151153

154+
### Using Overlapped Ring Buffer
152155

156+
Since v2.2.0, `NewOverlappedRingBuffer()` can initiate a different ring buffer, which
157+
allows us to overwrite the head element if putting new element into a **full** ring buffer.
153158

154-
155-
156-
157-
159+
```go
160+
func testStringRB() {
161+
var err error
162+
var rb = ringbuf.NewOverlappedRingBuffer[string](80)
163+
err = rb.Enqueue("abcde")
164+
errChk(err)
165+
166+
var item string
167+
item, err = rb.Dequeue()
168+
errChk(err)
169+
fmt.Printf("dequeue ok: %v\n", item)
170+
}
171+
```
158172

159173
## Contrib
160174

161175
Welcome
162176

163-
164177
## LICENSE
165178

166179
Apache 2.0

doc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const (
99
// AppName const
1010
AppName = "ringbuf"
1111
// Version const
12-
Version = "2.1.0"
12+
Version = "2.2.0"
1313
// VersionInt const
14-
VersionInt = 0x020100
14+
VersionInt = 0x020200
1515
)

0 commit comments

Comments
 (0)