MCPcopy Index your code
hub / github.com/Allenxuxu/ringbuffer

github.com/Allenxuxu/ringbuffer @v0.0.11

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0.11 ↗ · + Follow
57 symbols 265 edges 6 files 13 documented · 23% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ringbuffer

自动扩容的循环缓冲区实现

Github Actions Go Report Card Codacy Badge GoDoc LICENSE Code Size

使用

package main

import (
    "fmt"
    "github.com/Allenxuxu/ringbuffer"
)

func main() {
    rb := ringbuffer.New(2)

    // 自动扩容
    fmt.Println(rb.Capacity())  //2
    fmt.Println(rb.Length())    //0

    rb.Write([]byte("ab"))
    fmt.Println(rb.Capacity())  //2
    fmt.Println(rb.Length())    //2

    rb.Write([]byte("cd"))
    fmt.Println(rb.Capacity())  //4
    fmt.Println(rb.Length())    //4

    // VirtualXXX 函数便捷操作
    rb = New(1024)
    _, _ = rb.Write([]byte("abcd"))
    fmt.Println(rb.Length())
    fmt.Println(rb.free())
    buf := make([]byte, 4)

    _, _ = rb.Read(buf)
    fmt.Println(string(buf))

    rb.Write([]byte("1234567890"))
    rb.VirtualRead(buf)
    fmt.Println(string(buf))
    fmt.Println(rb.Length())
    fmt.Println(rb.VirtualLength())
    rb.VirtualFlush()
    fmt.Println(rb.Length())
    fmt.Println(rb.VirtualLength())

    rb.VirtualRead(buf)
    fmt.Println(string(buf))
    fmt.Println(rb.Length())
    fmt.Println(rb.VirtualLength())
    rb.VirtualRevert()
    fmt.Println(rb.Length())
    fmt.Println(rb.VirtualLength())
    // Output: 4
    // 1020
    // abcd
    // 1234
    // 10
    // 6
    // 6
    // 6
    // 5678
    // 6
    // 2
    // 6
    // 6
}

参考

https://github.com/smallnest/ringbuffer

感谢

Core symbols most depended-on inside this repo

Length
called by 60
ring_buffer.go
free
called by 43
ring_buffer.go
Bytes
called by 26
ring_buffer.go
Write
called by 21
ring_buffer.go
IsFull
called by 14
ring_buffer.go
IsEmpty
called by 13
ring_buffer.go
New
called by 11
ring_buffer.go
Read
called by 10
ring_buffer.go

Shape

Method 33
Function 20
Struct 3
TypeAlias 1

Languages

Go100%

Modules by API surface

ring_buffer.go31 symbols
pool.go12 symbols
ring_buffer_test.go10 symbols
pool_test.go2 symbols
ring_buffer_benchmark_test.go1 symbols
example_test.go1 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add ringbuffer \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact