entrydb

package
v1.13.7 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binary added in v1.9.5

type Binary[T EntryType, E Entry[T]] interface {
	Append(dest []byte, e *E) []byte
	ReadAt(dest *E, r io.ReaderAt, at int64) (n int, err error)
	EntrySize() int
}

Binary is the binary interface to encode/decode/size entries. This should be a zero-cost abstraction, and is bundled as interface for the EntryDB to have generic access to this functionality without const-generics for array size in Go.

type Entry

type Entry[T EntryType] interface {
	Type() T
	comparable
}

type EntryDB

type EntryDB[T EntryType, E Entry[T], B Binary[T, E]] struct {
	// contains filtered or unexported fields
}

func NewEntryDB

func NewEntryDB[T EntryType, E Entry[T], B Binary[T, E]](logger log.Logger, path string) (*EntryDB[T, E, B], error)

NewEntryDB creates an EntryDB. A new file will be created if the specified path does not exist, but parent directories will not be created. If the file exists it will be used as the existing data. Returns ErrRecoveryRequired if the existing file is not a valid entry db. A EntryDB is still returned but all operations will return ErrRecoveryRequired until the Recover method is called.

func (*EntryDB[T, E, B]) Append

func (e *EntryDB[T, E, B]) Append(entries ...E) error

Append entries to the database. The entries are combined in memory and passed to a single Write invocation. If the write fails, it will attempt to truncate any partially written data. Subsequent writes to this instance will fail until partially written data is truncated.

func (*EntryDB[T, E, B]) Close

func (e *EntryDB[T, E, B]) Close() error

func (*EntryDB[T, E, B]) LastEntryIdx

func (e *EntryDB[T, E, B]) LastEntryIdx() EntryIdx

LastEntryIdx returns the index of the last entry in the DB. This returns -1 if the DB is empty.

func (*EntryDB[T, E, B]) Read

func (e *EntryDB[T, E, B]) Read(idx EntryIdx) (E, error)

Read an entry from the database by index. Returns io.EOF iff idx is after the last entry.

func (*EntryDB[T, E, B]) Size

func (e *EntryDB[T, E, B]) Size() int64

func (*EntryDB[T, E, B]) Truncate

func (e *EntryDB[T, E, B]) Truncate(idx EntryIdx) error

Truncate the database so that the last retained entry is idx. Any entries after idx are deleted.

type EntryIdx

type EntryIdx int64

type EntryStore added in v1.9.5

type EntryStore[T EntryType, E Entry[T]] interface {
	Size() int64
	LastEntryIdx() EntryIdx
	Read(idx EntryIdx) (E, error)
	Append(entries ...E) error
	Truncate(idx EntryIdx) error
	Close() error
}

type EntryType added in v1.9.3

type EntryType interface {
	String() string
	~uint8
}

type MemEntryStore added in v1.9.5

type MemEntryStore[T EntryType, E Entry[T]] struct {
	// contains filtered or unexported fields
}

func (*MemEntryStore[T, E]) Append added in v1.9.5

func (s *MemEntryStore[T, E]) Append(entries ...E) error

func (*MemEntryStore[T, E]) Close added in v1.9.5

func (s *MemEntryStore[T, E]) Close() error

func (*MemEntryStore[T, E]) LastEntryIdx added in v1.9.5

func (s *MemEntryStore[T, E]) LastEntryIdx() EntryIdx

func (*MemEntryStore[T, E]) Read added in v1.9.5

func (s *MemEntryStore[T, E]) Read(idx EntryIdx) (E, error)

func (*MemEntryStore[T, E]) Size added in v1.9.5

func (s *MemEntryStore[T, E]) Size() int64

func (*MemEntryStore[T, E]) Truncate added in v1.9.5

func (s *MemEntryStore[T, E]) Truncate(idx EntryIdx) error

Jump to

Keyboard shortcuts

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