buffer

package
v2.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package buffer

(C) Copyright Alex Gaetano Padula

Licensed under the Mozilla Public License, v. 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.mozilla.org/en-US/MPL/2.0/

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is a concurrent lock-free buffer with ID/Slot-based access

func New

func New(capacity int) (*Buffer, error)

New creates a new atomic buffer with the specified capacity

func (*Buffer) Add

func (buff *Buffer) Add(item interface{}) (int64, error)

Add attempts to add an item to the buffer

func (*Buffer) Capacity

func (buff *Buffer) Capacity() int64

Capacity returns the maximum capacity of the buffer

func (*Buffer) Count

func (buff *Buffer) Count() int64

Count returns the number of items currently in the buffer

func (*Buffer) ForEach

func (buff *Buffer) ForEach(f func(slot int64, item interface{}) bool)

ForEach applies function f to each item in the buffer Returns early if f returns false *This is not atomic across all slots

func (*Buffer) Get

func (buff *Buffer) Get(slot int64) (interface{}, error)

Get retrieves an item by its slot ID

func (*Buffer) IsEmpty

func (buff *Buffer) IsEmpty() bool

IsEmpty returns true if the buffer contains no items

func (*Buffer) IsFull

func (buff *Buffer) IsFull() bool

IsFull returns true if the buffer is at capacity

func (*Buffer) List

func (buff *Buffer) List() []interface{}

List returns a snapshot of all non-nil values in the buffer *This is not atomic across all slots, so it provides a point-in-time view

func (*Buffer) Remove

func (buff *Buffer) Remove(slot int64) error

Remove removes an item by its slot ID

func (*Buffer) Update

func (buff *Buffer) Update(slot int64, newValue interface{}) error

Update atomically updates an item at the given slot

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL