set

package
v0.0.0-...-8103da3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2017 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCollision = errors.New("key already exists")

Returned when an added key already exists in the set.

View Source
var ErrMissing = errors.New("item does not exist")

Returned when a requested item does not exist in the set.

View Source
var ErrNil = errors.New("item value must not be nil")

Returned when a nil item is added. Nil values are considered expired and invalid.

Functions

This section is empty.

Types

type ExpiringItem

type ExpiringItem struct {
	Item
	time.Time
}

func (*ExpiringItem) Expired

func (item *ExpiringItem) Expired() bool

func (*ExpiringItem) Value

func (item *ExpiringItem) Value() interface{}

type Item

type Item interface {
	Key() string
	Value() interface{}
}

Interface for an item storeable in the set

func Expire

func Expire(item Item, d time.Duration) Item

func Itemize

func Itemize(key string, value interface{}) Item

type IterFunc

type IterFunc func(key string, item Item) error

type Set

type Set struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New() *Set

New creates a new set with case-insensitive keys

func (*Set) Add

func (s *Set) Add(item Item) error

Add item to this set if it does not exist already.

func (*Set) Clear

func (s *Set) Clear() int

Clear removes all items and returns the number removed.

func (*Set) Each

func (s *Set) Each(fn IterFunc) error

Each loops over every item while holding a read lock and applies fn to each element.

func (*Set) Get

func (s *Set) Get(key string) (Item, error)

Get returns an item with the given key.

func (*Set) In

func (s *Set) In(key string) bool

In checks if an item exists in this set.

func (*Set) Len

func (s *Set) Len() int

Len returns the size of the set right now.

func (*Set) ListPrefix

func (s *Set) ListPrefix(prefix string) []Item

ListPrefix returns a list of items with a prefix, normalized. TODO: Add trie for efficient prefix lookup

func (*Set) Remove

func (s *Set) Remove(key string) error

Remove item from this set.

func (*Set) Replace

func (s *Set) Replace(oldKey string, item Item) error

Replace oldKey with a new item, which might be a new key. Can be used to rename items.

type StringItem

type StringItem string

func (StringItem) Key

func (item StringItem) Key() string

func (StringItem) Value

func (item StringItem) Value() interface{}

Jump to

Keyboard shortcuts

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