hash

package
v0.0.0-...-8a7ea67 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package hash implements a simple storage agnostic hash index for a key value store.

- no segmentation / compaction - implies that keys can and will appear multiple times, the most recent entry will reflect the actual state in the keys - uses single append only log (can grow boundlessly with no segmentation / compaction) - keeps entire keyset in an in-memory map (keys) - keys maps a keys hash to its corresponding log entry's location in the underlying paginated storage

Operations: - get - set - del - restore -> restore the keys map from the commit log

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHash

func DefaultHash(key []byte) (string, error)

DefaultHash is a HashFunc that uses the sha1 hashing algorithm

func NoHash

func NoHash(key []byte) (string, error)

NoHash is a HashFunc that returns the key as a string without hashing.

Types

type Index

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

Index is a hash index implementation

func NewIndex

func NewIndex(log *logrus.Logger, store storage.Storer, opts ...IndexOption) (*Index, error)

NewIndex accepts a variadic number of option funcs for configuration. It returns a configured Hash Index ready to start running operations.

func (*Index) Del

func (i *Index) Del(key string) error

Del removes the key from the keys.

func (*Index) Get

func (i *Index) Get(key string) (string, error)

Get gets the value at key in the log and returns the value or an error if it wasn't found.

func (*Index) Set

func (i *Index) Set(key string, val string) error

Set sets key to val, it returns an error if the operation is unsuccessful.

type IndexOption

type IndexOption func(*options)

IndexOption is func that modifies the index configuration options.

func SetHashFunc

func SetHashFunc(hash KeyHashFunc) IndexOption

SetHashFunc overrides the Index default hashing func.

type KeyHashFunc

type KeyHashFunc func(key []byte) (string, error)

KeyHashFunc is a hash func that takes a slice of bytes and returns a hash or an error

Jump to

Keyboard shortcuts

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