Documentation ¶
Overview ¶
Package collections provides some typical and often used collection types like a ring buffer, stacks, sets and trees. They are implemented as generic collections managing empty interfaces as well as typed ones, e.g. for strings. They are not synchronized, so this has to be done by the user.
Index ¶
- type Changer
- type KeyStringValue
- type KeyStringValueChanger
- func (c *KeyStringValueChanger) Add(k, v string) error
- func (c *KeyStringValueChanger) Error() error
- func (c *KeyStringValueChanger) Key() (string, error)
- func (c *KeyStringValueChanger) List() ([]KeyStringValue, error)
- func (c *KeyStringValueChanger) Remove() error
- func (c *KeyStringValueChanger) SetKey(key string) (string, error)
- func (c *KeyStringValueChanger) SetValue(value string) (string, error)
- func (c *KeyStringValueChanger) Value() (string, error)
- type KeyStringValueTree
- func (t *KeyStringValueTree) At(keys ...string) *KeyStringValueChanger
- func (t *KeyStringValueTree) Copy() *KeyStringValueTree
- func (t *KeyStringValueTree) CopyAt(keys ...string) (*KeyStringValueTree, error)
- func (t *KeyStringValueTree) Create(keys ...string) *KeyStringValueChanger
- func (t *KeyStringValueTree) Deflate(k, v string)
- func (t *KeyStringValueTree) DoAll(f func(k, v string) error) error
- func (t *KeyStringValueTree) DoAllDeep(f func(ks []string, v string) error) error
- func (t *KeyStringValueTree) FindAll(f func(k, v string) (bool, error)) []*KeyStringValueChanger
- func (t *KeyStringValueTree) FindFirst(f func(k, v string) (bool, error)) *KeyStringValueChanger
- func (t *KeyStringValueTree) Len() int
- func (t *KeyStringValueTree) Root() *KeyStringValueChanger
- func (t *KeyStringValueTree) String() string
- type KeyValue
- type KeyValueChanger
- func (c *KeyValueChanger) Add(k string, v interface{}) error
- func (c *KeyValueChanger) Error() error
- func (c *KeyValueChanger) Key() (string, error)
- func (c *KeyValueChanger) List() ([]KeyValue, error)
- func (c *KeyValueChanger) Remove() error
- func (c *KeyValueChanger) SetKey(key string) (string, error)
- func (c *KeyValueChanger) SetValue(value interface{}) (interface{}, error)
- func (c *KeyValueChanger) Value() (interface{}, error)
- type KeyValueTree
- func (t *KeyValueTree) At(keys ...string) *KeyValueChanger
- func (t *KeyValueTree) Copy() *KeyValueTree
- func (t *KeyValueTree) CopyAt(keys ...string) (*KeyValueTree, error)
- func (t *KeyValueTree) Create(keys ...string) *KeyValueChanger
- func (t *KeyValueTree) Deflate(k string, v interface{})
- func (t *KeyValueTree) DoAll(f func(k string, v interface{}) error) error
- func (t *KeyValueTree) DoAllDeep(f func(ks []string, v interface{}) error) error
- func (t *KeyValueTree) FindAll(f func(k string, v interface{}) (bool, error)) []*KeyValueChanger
- func (t *KeyValueTree) FindFirst(f func(k string, v interface{}) (bool, error)) *KeyValueChanger
- func (t *KeyValueTree) Len() int
- func (t *KeyValueTree) Root() *KeyValueChanger
- func (t *KeyValueTree) String() string
- type RingBuffer
- type Set
- func (s *Set) Add(vs ...interface{})
- func (s *Set) All() []interface{}
- func (s *Set) Contains(v interface{}) bool
- func (s *Set) Deflate()
- func (s *Set) DoAll(f func(v interface{}) error) error
- func (s *Set) FindAll(f func(v interface{}) (bool, error)) ([]interface{}, error)
- func (s *Set) Len() int
- func (s *Set) Remove(vs ...interface{})
- func (s *Set) String() string
- type Stack
- type StringChanger
- type StringSet
- func (s *StringSet) Add(vs ...string)
- func (s *StringSet) All() []string
- func (s *StringSet) Contains(v string) bool
- func (s *StringSet) Deflate()
- func (s *StringSet) DoAll(f func(v string) error) error
- func (s *StringSet) FindAll(f func(v string) (bool, error)) ([]string, error)
- func (s *StringSet) Len() int
- func (s *StringSet) Remove(vs ...string)
- func (s *StringSet) String() string
- type StringStack
- func (s *StringStack) All() []string
- func (s *StringStack) AllReverse() []string
- func (s *StringStack) Deflate()
- func (s *StringStack) Len() int
- func (s *StringStack) Peek() (string, error)
- func (s *StringStack) Pop() (string, error)
- func (s *StringStack) Push(vs ...string)
- func (s *StringStack) String() string
- type StringTree
- func (t *StringTree) At(values ...string) *StringChanger
- func (t *StringTree) Copy() *StringTree
- func (t *StringTree) Create(values ...string) *StringChanger
- func (t *StringTree) Deflate(v string)
- func (t *StringTree) DoAll(f func(v string) error) error
- func (t *StringTree) DoAllDeep(f func(vs []string) error) error
- func (t *StringTree) FindAll(f func(v string) (bool, error)) []*StringChanger
- func (t *StringTree) FindFirst(f func(v string) (bool, error)) *StringChanger
- func (t *StringTree) Len() int
- func (t *StringTree) Root() *StringChanger
- func (t *StringTree) String() string
- type Tree
- func (t *Tree) At(values ...interface{}) *Changer
- func (t *Tree) Copy() *Tree
- func (t *Tree) Create(values ...interface{}) *Changer
- func (t *Tree) Deflate(v interface{})
- func (t *Tree) DoAll(f func(v interface{}) error) error
- func (t *Tree) DoAllDeep(f func(vs []interface{}) error) error
- func (t *Tree) FindAll(f func(v interface{}) (bool, error)) []*Changer
- func (t *Tree) FindFirst(f func(v interface{}) (bool, error)) *Changer
- func (t *Tree) Len() int
- func (t *Tree) Root() *Changer
- func (t *Tree) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Changer ¶
type Changer struct {
// contains filtered or unexported fields
}
Changer defines the interface to perform changes on a tree node. It is returned by the addressing operations like At() and Create() of the Tree.
type KeyStringValue ¶
KeyStringValue carries a combination of key and string value.
type KeyStringValueChanger ¶
type KeyStringValueChanger struct {
// contains filtered or unexported fields
}
KeyStringValueChanger defines the interface to perform changes on a key/string value tree node. It is returned by the addressing operations like At() and Create() of the KeyStringValueTree.
func (*KeyStringValueChanger) Add ¶
func (c *KeyStringValueChanger) Add(k, v string) error
Add sets a child key/value. If the key already exists the value will be overwritten.
func (*KeyStringValueChanger) Error ¶
func (c *KeyStringValueChanger) Error() error
Error returns a potential error of the changer.
func (*KeyStringValueChanger) Key ¶
func (c *KeyStringValueChanger) Key() (string, error)
Key returns the changer node key.
func (*KeyStringValueChanger) List ¶
func (c *KeyStringValueChanger) List() ([]KeyStringValue, error)
List returns the keys and values of the children of the changer node.
func (*KeyStringValueChanger) Remove ¶
func (c *KeyStringValueChanger) Remove() error
Remove deletes this changer node.
func (*KeyStringValueChanger) SetKey ¶
func (c *KeyStringValueChanger) SetKey(key string) (string, error)
SetKey sets the changer node key. Its checks if duplicate keys are allowed and returns the previous key.
func (*KeyStringValueChanger) SetValue ¶
func (c *KeyStringValueChanger) SetValue(value string) (string, error)
SetValue sets the changer node value. It also returns the previous value.
func (*KeyStringValueChanger) Value ¶
func (c *KeyStringValueChanger) Value() (string, error)
Value returns the changer node value.
type KeyStringValueTree ¶
type KeyStringValueTree struct {
// contains filtered or unexported fields
}
KeyStringValueTree defines the interface for a tree able to store key/string value pairs.
func NewKeyStringValueTree ¶
func NewKeyStringValueTree(k, v string, duplicates bool) *KeyStringValueTree
NewKeyStringValueTree creates a new key/value tree with or without duplicate values for children and strings as values.
func (*KeyStringValueTree) At ¶
func (t *KeyStringValueTree) At(keys ...string) *KeyStringValueChanger
At returns the changer of the path defined by the given values. If it does not exist it will not be created. Use Create() here. So to set a child at a given node path do
err := tree.At("path", "one", "to", "use").Set(12345)
func (*KeyStringValueTree) Copy ¶
func (t *KeyStringValueTree) Copy() *KeyStringValueTree
Copy creates a copy of the tree.
func (*KeyStringValueTree) CopyAt ¶
func (t *KeyStringValueTree) CopyAt(keys ...string) (*KeyStringValueTree, error)
CopyAt creates a copy of a subtree.
func (*KeyStringValueTree) Create ¶
func (t *KeyStringValueTree) Create(keys ...string) *KeyStringValueChanger
Create returns the changer of the path defined by the given keys. If it does not exist it will be created, but at least the root key has to be correct.
func (*KeyStringValueTree) Deflate ¶
func (t *KeyStringValueTree) Deflate(k, v string)
Deflate cleans the tree with a new root value.
func (*KeyStringValueTree) DoAll ¶
func (t *KeyStringValueTree) DoAll(f func(k, v string) error) error
DoAll executes the passed function on all nodes.
func (*KeyStringValueTree) DoAllDeep ¶
func (t *KeyStringValueTree) DoAllDeep(f func(ks []string, v string) error) error
DoAllDeep executes the passed function on all nodes passing a deep list of keys ordered top-down.
func (*KeyStringValueTree) FindAll ¶
func (t *KeyStringValueTree) FindAll(f func(k, v string) (bool, error)) []*KeyStringValueChanger
FindAll returns all changers for the nodes found by the passed function.
func (*KeyStringValueTree) FindFirst ¶
func (t *KeyStringValueTree) FindFirst(f func(k, v string) (bool, error)) *KeyStringValueChanger
FindFirst returns the changer for the first node found by the passed function.
func (*KeyStringValueTree) Len ¶
func (t *KeyStringValueTree) Len() int
Len returns the number of nodes of the tree.
func (*KeyStringValueTree) Root ¶
func (t *KeyStringValueTree) Root() *KeyStringValueChanger
Root returns the top level changer.
func (*KeyStringValueTree) String ¶
func (t *KeyStringValueTree) String() string
String implements the fmt.Stringer interface.
type KeyValue ¶
type KeyValue struct { Keys string Value interface{} }
KeyValue wraps a key and a value for the key/value iterator.
type KeyValueChanger ¶
type KeyValueChanger struct {
// contains filtered or unexported fields
}
KeyValueChanger defines the interface to perform changes on a key/value tree node. It is returned by the addressing operations like At() and Create() of the KeyValueTree.
func (*KeyValueChanger) Add ¶
func (c *KeyValueChanger) Add(k string, v interface{}) error
Add sets a child key/value. If the key already exists the value will be overwritten.
func (*KeyValueChanger) Error ¶
func (c *KeyValueChanger) Error() error
Error returns a potential error of the changer.
func (*KeyValueChanger) Key ¶
func (c *KeyValueChanger) Key() (string, error)
Key returns the changer node key.
func (*KeyValueChanger) List ¶
func (c *KeyValueChanger) List() ([]KeyValue, error)
List returns the keys and values of the children of the changer node.
func (*KeyValueChanger) Remove ¶
func (c *KeyValueChanger) Remove() error
Remove deletes this changer node.
func (*KeyValueChanger) SetKey ¶
func (c *KeyValueChanger) SetKey(key string) (string, error)
SetKey sets the changer node key. Its checks if duplicate keys are allowed and returns the previous key.
func (*KeyValueChanger) SetValue ¶
func (c *KeyValueChanger) SetValue(value interface{}) (interface{}, error)
SetValue sets the changer node value. It also returns the previous value.
func (*KeyValueChanger) Value ¶
func (c *KeyValueChanger) Value() (interface{}, error)
Value returns the changer node value.
type KeyValueTree ¶
type KeyValueTree struct {
// contains filtered or unexported fields
}
KeyValueTree defines the interface for a tree able to store key/value pairs.
func NewKeyValueTree ¶
func NewKeyValueTree(k string, v interface{}, duplicates bool) *KeyValueTree
NewKeyValueTree creates a new key/value tree with or without duplicate values for children.
func (*KeyValueTree) At ¶
func (t *KeyValueTree) At(keys ...string) *KeyValueChanger
At returns the changer of the path defined by the given values. If it does not exist it will not be created. Use Create() here. So to set a child at a given node path do
err := tree.At("path", "one", "to", "use").Set(12345)
func (*KeyValueTree) Copy ¶
func (t *KeyValueTree) Copy() *KeyValueTree
Copy creates a copy of the tree.
func (*KeyValueTree) CopyAt ¶
func (t *KeyValueTree) CopyAt(keys ...string) (*KeyValueTree, error)
CopyAt creates a copy of a subtree.
func (*KeyValueTree) Create ¶
func (t *KeyValueTree) Create(keys ...string) *KeyValueChanger
Create returns the changer of the path defined by the given keys. If it does not exist it will be created, but at least the root key has to be correct.
func (*KeyValueTree) Deflate ¶
func (t *KeyValueTree) Deflate(k string, v interface{})
Deflate cleans the tree with a new root value.
func (*KeyValueTree) DoAll ¶
func (t *KeyValueTree) DoAll(f func(k string, v interface{}) error) error
DoAll executes the passed function on all nodes.
func (*KeyValueTree) DoAllDeep ¶
func (t *KeyValueTree) DoAllDeep(f func(ks []string, v interface{}) error) error
DoAllDeep executes the passed function on all nodes passing a deep list of keys ordered top-down.
func (*KeyValueTree) FindAll ¶
func (t *KeyValueTree) FindAll(f func(k string, v interface{}) (bool, error)) []*KeyValueChanger
FindAll returns all changers for the nodes found by the passed function.
func (*KeyValueTree) FindFirst ¶
func (t *KeyValueTree) FindFirst(f func(k string, v interface{}) (bool, error)) *KeyValueChanger
FindFirst returns the changer for the first node found by the passed function.
func (*KeyValueTree) Len ¶
func (t *KeyValueTree) Len() int
Len returns the number of nodes of the tree.
func (*KeyValueTree) Root ¶
func (t *KeyValueTree) Root() *KeyValueChanger
Root returns the top level changer.
func (*KeyValueTree) String ¶
func (t *KeyValueTree) String() string
String implements the fmt.Stringer interface.
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer defines a buffer which is connected end-to-end. It grows if needed.
func NewRingBuffer ¶
func NewRingBuffer(size int) *RingBuffer
NewRingBuffer creates a new ring buffer.
func (*RingBuffer) Len ¶
func (rb *RingBuffer) Len() int
Len returns the number of values in the buffer.
func (*RingBuffer) Peek ¶
func (rb *RingBuffer) Peek() (interface{}, bool)
Peek returns the first value of the buffer. If the buffer is empty the second return value is false.
func (*RingBuffer) Pop ¶
func (rb *RingBuffer) Pop() (interface{}, bool)
Pop removes and returns the first value of the buffer. If the buffer is empty the second return value is false.
func (*RingBuffer) Push ¶
func (rb *RingBuffer) Push(values ...interface{})
Push adds values to the end of the buffer.
func (*RingBuffer) String ¶
func (rb *RingBuffer) String() string
String implements the fmt.Stringer interface.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set defines a set containing any kind of values.
func NewSet ¶
func NewSet(vs ...interface{}) *Set
NewSet creates a set with the passed values as initial content.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack defines a stack containing any kind of values.
func NewStack ¶
func NewStack(vs ...interface{}) *Stack
NewStack creates a stack with the passed values as initial content.
func (*Stack) AllReverse ¶
func (s *Stack) AllReverse() []interface{}
AllReverse returns all values top-down.
type StringChanger ¶
type StringChanger struct {
// contains filtered or unexported fields
}
StringChanger defines the interface to perform changes on a string tree node. It is returned by the addressing operations like At() and Create() of the StringTree.
func (*StringChanger) Add ¶
func (c *StringChanger) Add(v string) error
Add sets a child value. If it already exists it will be overwritten.
func (*StringChanger) Error ¶
func (c *StringChanger) Error() error
Error returns a potential error of the changer.
func (*StringChanger) List ¶
func (c *StringChanger) List() ([]string, error)
List returns the values of the children of the changer node.
func (*StringChanger) Remove ¶
func (c *StringChanger) Remove() error
Remove deletes this changer node.
func (*StringChanger) SetValue ¶
func (c *StringChanger) SetValue(v string) (string, error)
SetValue sets the changer node value. It also returns the previous value.
func (*StringChanger) Value ¶
func (c *StringChanger) Value() (string, error)
Value returns the changer node value.
type StringSet ¶
type StringSet struct {
// contains filtered or unexported fields
}
StringSet defines a set containing string values.
func NewStringSet ¶
NewStringSet creates a string set with the passed strings as initial content.
type StringStack ¶
type StringStack struct {
// contains filtered or unexported fields
}
StringStack defines a stack containing string values.
func NewStringStack ¶
func NewStringStack(vs ...string) *StringStack
NewStringStack creates a string stack with the passed strings as initial content.
func (*StringStack) AllReverse ¶
func (s *StringStack) AllReverse() []string
AllReverse returns all strings top-down.
func (*StringStack) Len ¶
func (s *StringStack) Len() int
Len returns the number of entries in the stack.
func (*StringStack) Peek ¶
func (s *StringStack) Peek() (string, error)
Peek returns the top string of the stack.
func (*StringStack) Pop ¶
func (s *StringStack) Pop() (string, error)
Pop removes and returns the top string of the stack.
func (*StringStack) Push ¶
func (s *StringStack) Push(vs ...string)
Push adds strings to the top of the stack.
func (*StringStack) String ¶
func (s *StringStack) String() string
String implements the fmt.Stringer interface.
type StringTree ¶
type StringTree struct {
// contains filtered or unexported fields
}
StringTree defines the interface for a tree able to store strings.
func NewStringTree ¶
func NewStringTree(v string, duplicates bool) *StringTree
NewStringTree creates a new string tree with or without duplicate values for children.
func (*StringTree) At ¶
func (t *StringTree) At(values ...string) *StringChanger
At returns the changer of the path defined by the given values. If it does not exist it will not be created. Use Create() here. So to set a child at a given node path do
err := tree.At("path", "one", "to", "use").Set("12345")
func (*StringTree) Create ¶
func (t *StringTree) Create(values ...string) *StringChanger
Create returns the changer of the path defined by the given keys. If it does not exist it will be created, but at least the root key has to be correct.
func (*StringTree) Deflate ¶
func (t *StringTree) Deflate(v string)
Deflate cleans the tree with a new root value.
func (*StringTree) DoAll ¶
func (t *StringTree) DoAll(f func(v string) error) error
DoAll executes the passed function on all nodes.
func (*StringTree) DoAllDeep ¶
func (t *StringTree) DoAllDeep(f func(vs []string) error) error
DoAllDeep executes the passed function on all nodes passing a deep list of values ordered top-down.
func (*StringTree) FindAll ¶
func (t *StringTree) FindAll(f func(v string) (bool, error)) []*StringChanger
FindAll returns all changers for the nodes found by the passed function.
func (*StringTree) FindFirst ¶
func (t *StringTree) FindFirst(f func(v string) (bool, error)) *StringChanger
FindFirst returns the changer for the first node found by the passed function.
func (*StringTree) Len ¶
func (t *StringTree) Len() int
Len returns the number of nodes of the tree.
func (*StringTree) Root ¶
func (t *StringTree) Root() *StringChanger
Root returns the top level changer.
func (*StringTree) String ¶
func (t *StringTree) String() string
String implements the fmt.Stringer interface.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree defines the interface for a tree able to store any type of values.
func (*Tree) At ¶
At returns the changer of the path defined by the given values. If it does not exist it will not be created. Use Create() here. So to set a child at a given node path do
err := tree.At("path", 1, "to", "use").Set(12345)
func (*Tree) Create ¶
Create returns the changer of the path defined by the given keys. If it does not exist it will be created, but at least the root key has to be correct.
func (*Tree) Deflate ¶
func (t *Tree) Deflate(v interface{})
Deflate cleans the tree with a new root value.
func (*Tree) DoAllDeep ¶
DoAllDeep executes the passed function on all nodes passing a deep list of values ordered top-down.