circular

package
v0.0.0-...-dfb750a Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: Apache-2.0 Imports: 0 Imported by: 1

README

Package cloudeng.io/algo/container/circular

import cloudeng.io/algo/container/circular

Package circular provides 'circular' data structures,

Types

Type Buffer
type Buffer[T any] struct {
	// contains filtered or unexported fields
}

Buffer provides a circular buffer that grows as needed.

Functions
func NewBuffer[T any](size int) *Buffer[T]

NewBuffer creates a new buffer with the specified initial size.

Methods
func (b *Buffer[T]) Append(v []T)

Append appends the specified values to the buffer, growing the buffer as needed.

func (b *Buffer[T]) Cap() int

Cap returns the current capacity of the buffer.

func (b *Buffer[T]) Compact()

Compact reduces the storage used by the buffer to the minimum necessary to store its current contents. This also has the effect of freeing any pointers that are no longer accessible via the buffer and hence may be GC'd.

func (b *Buffer[T]) Head(n int) []T

Head returns the first n elements of the buffer, removing them from the buffer. If n is greater than the number of elements in the buffer then all elements are returned. The values returned are not zeroed out and hence if pointers will not be GC'd until the buffer itself is released or Compact is called.

func (b *Buffer[T]) Len() int

Len returns the current number of elements in the buffer.

Documentation

Overview

Package circular provides 'circular' data structures,

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer[T any] struct {
	// contains filtered or unexported fields
}

Buffer provides a circular buffer that grows as needed.

func NewBuffer

func NewBuffer[T any](size int) *Buffer[T]

NewBuffer creates a new buffer with the specified initial size.

func (*Buffer[T]) Append

func (b *Buffer[T]) Append(v []T)

Append appends the specified values to the buffer, growing the buffer as needed.

func (*Buffer[T]) Cap

func (b *Buffer[T]) Cap() int

Cap returns the current capacity of the buffer.

func (*Buffer[T]) Compact

func (b *Buffer[T]) Compact()

Compact reduces the storage used by the buffer to the minimum necessary to store its current contents. This also has the effect of freeing any pointers that are no longer accessible via the buffer and hence may be GC'd.

func (*Buffer[T]) Head

func (b *Buffer[T]) Head(n int) []T

Head returns the first n elements of the buffer, removing them from the buffer. If n is greater than the number of elements in the buffer then all elements are returned. The values returned are not zeroed out and hence if pointers will not be GC'd until the buffer itself is released or Compact is called.

func (*Buffer[T]) Len

func (b *Buffer[T]) Len() int

Len returns the current number of elements in the buffer.

Jump to

Keyboard shortcuts

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