fileArray

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileArray

type FileArray[T serialization.Serializer[T]] struct {
	// contains filtered or unexported fields
}

func NewFileArray

func NewFileArray[T serialization.Serializer[T]](filename string, readOnly bool) (*FileArray[T], error)

NewFileArray initializes a new FileArray instance.

Parameters:

  • serializer: The serializer used to serialize data.
  • filename: The path to the backing file.

Returns:

  • *FileArray: A pointer to the FileArray instance.
  • error: An error if initialization fails.

func (*FileArray[T]) Append

func (fileArray *FileArray[T]) Append(item T) (serialization.Offset, error)

Append appends an item of type T to a FileArray. It serializes the item and adds it to the end of the array.

Parameters:

  • item: The item of type T to be appended.

Returns:

  • An error if the operation fails, nil otherwise.

func (*FileArray[T]) Close

func (fileArray *FileArray[T]) Close() error

Close unmaps the memory-mapped region and closes the backing file.

Returns:

  • error: An error if unmap or file close operations fail.

func (*FileArray[T]) Count

func (fileArray *FileArray[T]) Count() serialization.Length

Count returns the current count of elements stored in the FileArray instance.

func (*FileArray[T]) Expand

func (fileArray *FileArray[T]) Expand(items serialization.Length) error

Expand increases the size of the memory-mapped region by the specified number of items.

func (*FileArray[T]) GetFileName

func (fileArray *FileArray[T]) GetFileName() string

GetFileName returns the name of the backing file.

func (*FileArray[T]) GetItemFromIndex

func (fileArray *FileArray[T]) GetItemFromIndex(index serialization.Offset) (T, error)

GetItemFromIndex retrieves an item of type T from a FileArray at the specified index. It deserializes the item and returns it along with any potential errors.

Parameters:

  • index: The index of the item to retrieve.

Returns:

  • The item of type T at the specified index.
  • An error if the operation fails, nil otherwise.

func (*FileArray[T]) Prefetch

func (fileArray *FileArray[T]) Prefetch()

func (*FileArray[T]) Reopen

func (fileArray *FileArray[T]) Reopen(readOnly bool) error

func (*FileArray[T]) SetItemAtIndex

func (fileArray *FileArray[T]) SetItemAtIndex(item T, index serialization.Offset) error

SetItemAtIndex sets an item of type T at a specific index within a FileArray. It serializes the item and stores it at the given index.

Parameters:

  • item: The item of type T to be set.
  • index: The index where the item will be placed.

Returns:

  • An error if the operation fails, nil otherwise.

func (*FileArray[T]) ShrinkWrap

func (fileArray *FileArray[T]) ShrinkWrap() error

ShrinkWrap reduces the size of a FileArray to match the actual data size. It is used to optimize disk usage by resizing the array to fit its contents.

Returns:

  • An error if the operation fails, nil otherwise.

func (*FileArray[T]) Unmap

func (fileArray *FileArray[T]) Unmap() error
type Header struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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