bytes

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright 2023 The acquirecloud Authors

Licensed under the Apache License, Version 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

http://www.apache.org/licenses/LICENSE-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.

bytes package provides the Buffer interface for accessing to bytes storage, which may be a quite big. It can be used for building data indexes on top of filesystem and store trees into a file via the Bytes interface.

Licensed under the Apache License, Version 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

http://www.apache.org/licenses/LICENSE-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

func GetBlocksInSegment

func GetBlocksInSegment(blkSize int) int

GetBlocksInSegment returns the absolute number (including header) of blocks that may be in a segment with the size of each block = blkSize. It returns -1 if blkSize invalid (not acceptable)

func NewInMemBytes

func NewInMemBytes(size int) *inmemBtsBuf

Types

type Blocks

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

Blocks struct allows to organize a byte-blocks storage on top of a Buffer storage. The blocks have a constant size and the Blocks allow to allocate (ArrangeBlock) or free previously allocated blocks.

Blocks split bts on to set of blocks called segment. Every segment contains fixed number of blocks. First block in each segment is called header, and it contains information about allocated blocks in the segment. Header contains blkSize*8 bits, so one segment can contain blkSize*8 blocks + 1 block for the header.

func NewBlocks

func NewBlocks(bs int, bts Buffer, fit bool) (*Blocks, error)

NewBlocks creates the new Blocks on top of Bytes storage. The storage should be opened, and it has to have appropriate size, so the blocks could properly fit there Params:

	bs 	- specifies one block size
	bts - the Bytes storage
 fit - specifies the bts.Size() must match exactly to the block storage expectations.
			if the fit is false, the bts storage can be larger than expected.

func (*Blocks) ArrangeBlock

func (bks *Blocks) ArrangeBlock() (int, error)

ArrangeBlock arranges a new empty block and return its index. The function returns ErrExhausted error if no available blocks in the storage anymore

func (*Blocks) Available

func (bks *Blocks) Available() int

Available returns number of free blocks.

func (*Blocks) Block

func (bks *Blocks) Block(idx int) ([]byte, error)

Block returns a block value, or if the index is out of range, or access to the block is not possible

func (*Blocks) Bytes

func (bks *Blocks) Bytes() Buffer

Bytes returns underlying Bytes storage

func (*Blocks) Close

func (bks *Blocks) Close() error

Close allows to close the Blocks storage

func (*Blocks) Completion

func (bks *Blocks) Completion() float32

Completion returns (Count() - Available())/Count() the value in [0..1]

func (*Blocks) Count

func (bks *Blocks) Count() int

Count returns total number of blocks

func (*Blocks) FreeBlock

func (bks *Blocks) FreeBlock(idx int) error

FreeBlock releases the block by its idx

func (*Blocks) Segments

func (bks *Blocks) Segments() int

Segments returns number of segments available

func (*Blocks) String

func (bks *Blocks) String() string

type Buffer

type Buffer interface {
	io.Closer

	// Size returns the current storage size.
	Size() int64

	// Grow allows to increase the storage size.
	Grow(newSize int64) error

	// Buffer returns a segment of the Bytes storage as a slice.
	// The slice can be read and written. The data written to the slice will be
	// saved in the Bytes buffer. Different goroutines are allowed
	// to request not overlapping buffers. Writing to the same segment
	// from different go routines causes unpredictable result.
	Buffer(offs int64, size int) ([]byte, error)
}

Buffer interface provides access to a byte storage

Jump to

Keyboard shortcuts

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