circularbuffer

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type C2

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

C2 is a circular buffer intended to allow you to write a block of data of up to 'blocksize', and retrieve the data evicted by that operation, without allocating any extra slice storage

This requires that it keep at least blocksize*2 data around. In fact, it doubles that again in order to guarantee that both of these bits of information can always be obtained in a single contiguous block of memory.

Other than the cost of the extra memory (4xblocksize), this means that it requires 2 writes for every byte stored.

func MakeC2Buffer

func MakeC2Buffer(blockSize int) *C2

func (*C2) Empty

func (c *C2) Empty() bool

func (*C2) Evicted

func (c *C2) Evicted() []byte

get the data that was evicted by the last write

func (*C2) GetBlock

func (c *C2) GetBlock() []byte

get the current buffer contents of block

func (*C2) Len

func (c *C2) Len() int

func (*C2) Reset

func (c *C2) Reset()

func (*C2) Truncate

func (c *C2) Truncate(byteCount int) (evicted []byte)

Shortens the content of the circular buffer and returns the content removed

func (*C2) Write

func (c *C2) Write(b []byte) (n int, err error)

Write new data

Jump to

Keyboard shortcuts

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