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.
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.
Index ¶
- func GetBlocksInSegment(blkSize int) int
- func NewInMemBytes(size int) *inmemBtsBuf
- type Blocks
- func (bks *Blocks) ArrangeBlock() (int, error)
- func (bks *Blocks) Available() int
- func (bks *Blocks) Block(idx int) ([]byte, error)
- func (bks *Blocks) Bytes() Buffer
- func (bks *Blocks) Close() error
- func (bks *Blocks) Completion() float32
- func (bks *Blocks) Count() int
- func (bks *Blocks) FreeBlock(idx int) error
- func (bks *Blocks) Segments() int
- func (bks *Blocks) String() string
- type Buffer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBlocksInSegment ¶
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 ¶
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 ¶
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) Block ¶
Block returns a block value, or if the index is out of range, or access to the block is not possible
func (*Blocks) Completion ¶
Completion returns (Count() - Available())/Count() the value in [0..1]
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