Documentation ¶
Overview ¶
Package linkedhashset is a set that preserves insertion-order.
It is backed by a hash table to store values and doubly-linked list to store ordering.
Note that insertion-order is not affected if an element is re-inserted into the set.
Structure is not thread safe.
References: http://en.wikipedia.org/wiki/Set_%28abstract_data_type%29
Index ¶
- type Iterator
- func (iterator *Iterator) Begin()
- func (iterator *Iterator) End()
- func (iterator *Iterator) First() bool
- func (iterator *Iterator) Index() int
- func (iterator *Iterator) Last() bool
- func (iterator *Iterator) Next() bool
- func (iterator *Iterator) NextTo(f func(index int, value interface{}) bool) bool
- func (iterator *Iterator) Prev() bool
- func (iterator *Iterator) PrevTo(f func(index int, value interface{}) bool) bool
- func (iterator *Iterator) Value() interface{}
- type Set
- func (set *Set) Add(items ...interface{})
- func (set *Set) All(f func(index int, value interface{}) bool) bool
- func (set *Set) Any(f func(index int, value interface{}) bool) bool
- func (set *Set) Clear()
- func (set *Set) Contains(items ...interface{}) bool
- func (set *Set) Each(f func(index int, value interface{}))
- func (set *Set) Empty() bool
- func (set *Set) Find(f func(index int, value interface{}) bool) (int, interface{})
- func (set *Set) FromJSON(data []byte) error
- func (set *Set) Iterator() Iterator
- func (set *Set) Map(f func(index int, value interface{}) interface{}) *Set
- func (set *Set) Remove(items ...interface{})
- func (set *Set) Select(f func(index int, value interface{}) bool) *Set
- func (set *Set) Size() int
- func (set *Set) String() string
- func (set *Set) ToJSON() ([]byte, error)
- func (set *Set) Values() []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator holding the iterator's state
func (*Iterator) Begin ¶
func (iterator *Iterator) Begin()
Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.
func (*Iterator) End ¶
func (iterator *Iterator) End()
End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.
func (*Iterator) First ¶
First moves the iterator to the first element and returns true if there was a first element in the container. If First() returns true, then first element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) Index ¶
Index returns the current element's index. Does not modify the state of the iterator.
func (*Iterator) Last ¶
Last moves the iterator to the last element and returns true if there was a last element in the container. If Last() returns true, then last element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) Next ¶
Next moves the iterator to the next element and returns true if there was a next element in the container. If Next() returns true, then next element's index and value can be retrieved by Index() and Value(). If Next() was called for the first time, then it will point the iterator to the first element if it exists. Modifies the state of the iterator.
func (*Iterator) NextTo ¶ added in v1.13.0
NextTo moves the iterator to the next element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) Prev ¶
Prev moves the iterator to the previous element and returns true if there was a previous element in the container. If Prev() returns true, then previous element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) PrevTo ¶ added in v1.13.0
PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If PrevTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set holds elements in go's native map
func New ¶
func New(values ...interface{}) *Set
New instantiates a new empty set and adds the passed values, if any, to the set
func (*Set) Add ¶
func (set *Set) Add(items ...interface{})
Add adds the items (one or more) to the set. Note that insertion-order is not affected if an element is re-inserted into the set.
func (*Set) All ¶
All passes each element of the container to the given function and returns true if the function returns true for all elements.
func (*Set) Any ¶
Any passes each element of the container to the given function and returns true if the function ever returns true for any element.
func (*Set) Contains ¶
Contains check if items (one or more) are present in the set. All items have to be present in the set for the method to return true. Returns true if no arguments are passed at all, i.e. set is always superset of empty set.
func (*Set) Each ¶
Each calls the given function once for each element, passing that element's index and value.
func (*Set) Find ¶
Find passes each element of the container to the given function and returns the first (index,value) for which the function is true or -1,nil otherwise if no element matches the criteria.
func (*Set) Iterator ¶
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*Set) Map ¶
Map invokes the given function once for each element and returns a container containing the values returned by the given function.
func (*Set) Remove ¶
func (set *Set) Remove(items ...interface{})
Remove removes the items (one or more) from the set. Slow operation, worst-case O(n^2).
func (*Set) Select ¶
Select returns a new container containing all elements for which the given function returns a true value.