MCPcopy Create free account
hub / github.com/Allenxuxu/ringbuffer / ExampleRingBuffer

Function ExampleRingBuffer

example_test.go:5–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import "fmt"
4
5func ExampleRingBuffer() {
6 rb := New(1024)
7 _, _ = rb.Write([]byte("abcd"))
8 fmt.Println(rb.Length())
9 fmt.Println(rb.free())
10 buf := make([]byte, 4)
11
12 _, _ = rb.Read(buf)
13 fmt.Println(string(buf))
14
15 rb.Write([]byte("1234567890"))
16 rb.VirtualRead(buf)
17 fmt.Println(string(buf))
18 fmt.Println(rb.Length())
19 fmt.Println(rb.VirtualLength())
20 rb.VirtualFlush()
21 fmt.Println(rb.Length())
22 fmt.Println(rb.VirtualLength())
23
24 rb.VirtualRead(buf)
25 fmt.Println(string(buf))
26 fmt.Println(rb.Length())
27 fmt.Println(rb.VirtualLength())
28 rb.VirtualRevert()
29 fmt.Println(rb.Length())
30 fmt.Println(rb.VirtualLength())
31 // Output: 4
32 // 1020
33 // abcd
34 // 1234
35 // 10
36 // 6
37 // 6
38 // 6
39 // 5678
40 // 6
41 // 2
42 // 6
43 // 6
44}

Callers

nothing calls this directly

Calls 9

NewFunction · 0.85
WriteMethod · 0.80
LengthMethod · 0.80
freeMethod · 0.80
ReadMethod · 0.80
VirtualReadMethod · 0.80
VirtualLengthMethod · 0.80
VirtualFlushMethod · 0.80
VirtualRevertMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…