kv

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pair

type Pair struct {
	Key, Value string
}

type Storage

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

Storage is an associative structure for storing (string, string) pairs. It acts as a map but uses linear search instead, which proves to be more efficient on relatively low amount of entries, which often enough is the case.

func New

func New() *Storage

func NewFromMap

func NewFromMap(m map[string][]string) *Storage

NewFromMap returns a new instance with already inserted values from given map. Note: as maps are unordered, resulting underlying structure will also contain unordered pairs.

func NewFromPairs added in v0.17.2

func NewFromPairs(pairs []Pair) *Storage

NewFromPairs returns a new instance backed by the passed pairs as-is, without copying it. Use this method with care.

func NewPrealloc

func NewPrealloc(n int) *Storage

NewPrealloc returns an instance of Storage with pre-allocated underlying storage.

func (*Storage) Add

func (s *Storage) Add(key, value string) *Storage

Add adds a new pair of key and value.

func (*Storage) Clear

func (s *Storage) Clear() *Storage

Clear all the entries. However, all the allocated space won't be freed.

func (*Storage) Clone

func (s *Storage) Clone() *Storage

Clone creates a deep copy, which may be used later or stored somewhere safely. However, it comes at cost of multiple allocations.

func (*Storage) Delete added in v0.17.2

func (s *Storage) Delete(key string) *Storage

Delete quasi removes all the entries corresponding the key. In fact, an empty key is assigned to each eligible pair.

func (*Storage) Empty

func (s *Storage) Empty() bool

func (*Storage) Expose

func (s *Storage) Expose() []Pair

Expose exposes the underlying pairs slice. Unlike Pairs, it also contains all the deleted empty-key pairs

func (*Storage) Has

func (s *Storage) Has(key string) bool

Has indicates, whether there's an entry of the key.

func (*Storage) Keys

func (s *Storage) Keys() iter.Seq[string]

Keys returns an iterator over all the unique non-normalized keys.

func (*Storage) Len

func (s *Storage) Len() int

Len returns a number of stored pairs. Duplicate key entries are counted in.

func (*Storage) Lookup added in v0.17.2

func (s *Storage) Lookup(key string) (value string, found bool)

Lookup returns the first found value and indicates the success via a bool flag.

func (*Storage) Pairs added in v0.17.2

func (s *Storage) Pairs() iter.Seq2[string, string]

Pairs return an iterator over all the header field pairs presented. Multiple values are represented by occupying multiple pairs sharing the same key. Array values can occupy non-consecutive pairs.

func (*Storage) Set added in v0.17.2

func (s *Storage) Set(key, value string) *Storage

Set removes all the entries corresponding the key and sets the new value.

func (*Storage) Value

func (s *Storage) Value(key string) string

Value returns the first value, corresponding to the key. Otherwise, empty string is returned

func (*Storage) ValueOr

func (s *Storage) ValueOr(key, otherwise string) string

ValueOr returns either the first found value or the second parameter.

func (*Storage) Values

func (s *Storage) Values(key string) iter.Seq[string]

Values returns an iterator over all the values corresponding the given key.

Jump to

Keyboard shortcuts

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