Documentation ¶
Overview ¶
Package arraylist implements the array list.
Structure is not thread safe.
Reference: https://en.wikipedia.org/wiki/List_%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 List
- func (list *List) Add(values ...interface{})
- func (list *List) All(f func(index int, value interface{}) bool) bool
- func (list *List) Any(f func(index int, value interface{}) bool) bool
- func (list *List) Clear()
- func (list *List) Contains(values ...interface{}) bool
- func (list *List) Each(f func(index int, value interface{}))
- func (list *List) Empty() bool
- func (list *List) Find(f func(index int, value interface{}) bool) (int, interface{})
- func (list *List) FromJSON(data []byte) error
- func (list *List) Get(index int) (interface{}, bool)
- func (list *List) IndexOf(value interface{}) int
- func (list *List) Insert(index int, values ...interface{})
- func (list *List) Iterator() Iterator
- func (list *List) Map(f func(index int, value interface{}) interface{}) *List
- func (list *List) MarshalJSON() ([]byte, error)
- func (list *List) Remove(index int)
- func (list *List) Select(f func(index int, value interface{}) bool) *List
- func (list *List) Set(index int, value interface{})
- func (list *List) Size() int
- func (list *List) Sort(comparator utils.Comparator)
- func (list *List) String() string
- func (list *List) Swap(i, j int)
- func (list *List) ToJSON() ([]byte, error)
- func (list *List) UnmarshalJSON(bytes []byte) error
- func (list *List) 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 ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v1.1.0
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 List ¶
type List struct {
// contains filtered or unexported fields
}
List holds the elements in a slice
func New ¶
func New(values ...interface{}) *List
New instantiates a new list and adds the passed values, if any, to the list
func (*List) Add ¶
func (list *List) Add(values ...interface{})
Add appends a value at the end of the list
func (*List) All ¶
All passes each element of the collection to the given function and returns true if the function returns true for all elements.
func (*List) Any ¶
Any passes each element of the collection to the given function and returns true if the function ever returns true for any element.
func (*List) Contains ¶
Contains checks if elements (one or more) are present in the set. All elements have to be present in the set for the method to return true. Performance time complexity of n^2. Returns true if no arguments are passed at all, i.e. set is always super-set of empty set.
func (*List) Each ¶
Each calls the given function once for each element, passing that element's index and value.
func (*List) 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 (*List) FromJSON ¶ added in v1.9.0
FromJSON populates list's elements from the input JSON representation.
func (*List) Get ¶
Get returns the element at index. Second return parameter is true if index is within bounds of the array and array is not empty, otherwise false.
func (*List) Insert ¶
Insert inserts values at specified index position shifting the value at that position (if any) and any subsequent elements to the right. Does not do anything if position is negative or bigger than list's size Note: position equal to list's size is valid, i.e. append.
func (*List) Iterator ¶
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*List) Map ¶
Map invokes the given function once for each element and returns a container containing the values returned by the given function.
func (*List) MarshalJSON ¶ added in v1.15.0
MarshalJSON @implements json.Marshaler
func (*List) Select ¶
Select returns a new container containing all elements for which the given function returns a true value.
func (*List) Set ¶ added in v1.10.0
Set the value at specified index Does not do anything if position is negative or bigger than list's size Note: position equal to list's size is valid, i.e. append.
func (*List) Sort ¶
func (list *List) Sort(comparator utils.Comparator)
Sort sorts values (in-place) using.
func (*List) UnmarshalJSON ¶ added in v1.15.0
UnmarshalJSON @implements json.Unmarshaler