StateMate is a Go library designed for storing state as key-value pairs with efficient I/O operations and concurrency support.
- Memory-mapped files for efficient I/O.
- Thread-safe via read-write mutexes.
- Generics support for custom unsigned integer key types.
- Dynamic resizing of data and index files.
- Optional index gap allowance.
- Go 1.18 or higher for generics support.
Install the package using:
go get -u github.com/draganm/statemate
options := statemate.Options{ AllowGaps: true }
sm, err := statemate.Open[uint64]("datafile", options)
if err != nil {
// Handle error
}err := sm.Append(1, []byte("some data"))
if err != nil {
// Handle error
}err := sm.Read(1, func(data []byte) error {
// Process data
return nil
})
if err != nil {
// Handle error
}isEmpty := sm.IsEmpty()lastIndex := sm.LastIndex()ErrIndexMustBeIncreasing: The provided index must be greater than the last index.ErrIndexGapsAreNotAllowed: IfAllowGapsisfalse, indexes must be consecutive.ErrNotFound: The requested index was not found.
MIT License