ssh-chat: github.com/shazow/ssh-chat/set Index | Files

package set

import "github.com/shazow/ssh-chat/set"

Index

Package Files

item.go set.go

Variables

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

Returned when an added key already exists in the set.

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

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

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

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

type ExpiringItem Uses

type ExpiringItem struct {
    Item
    time.Time
}

func (*ExpiringItem) Expired Uses

func (item *ExpiringItem) Expired() bool

func (*ExpiringItem) Value Uses

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

type Item Uses

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

Interface for an item storeable in the set

func Expire Uses

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

func Itemize Uses

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

type IterFunc Uses

type IterFunc func(key string, item Item) error

type Set Uses

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

func New Uses

func New() *Set

New creates a new set with case-insensitive keys

func (*Set) Add Uses

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

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

func (*Set) Clear Uses

func (s *Set) Clear() int

Clear removes all items and returns the number removed.

func (*Set) Each Uses

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 Uses

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

Get returns an item with the given key.

func (*Set) In Uses

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

In checks if an item exists in this set.

func (*Set) Len Uses

func (s *Set) Len() int

Len returns the size of the set right now.

func (*Set) ListPrefix Uses

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 Uses

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

Remove item from this set.

func (*Set) Replace Uses

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.

func (*Set) Set Uses

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

Set item to this set, even if it already exists.

type StringItem Uses

type StringItem string

func (StringItem) Key Uses

func (item StringItem) Key() string

func (StringItem) Value Uses

func (item StringItem) Value() interface{}

Package set imports 4 packages (graph) and is imported by 12 packages. Updated 2018-12-28. Refresh now. Tools for package owners.