Documentation ¶
Index ¶
- Variables
- type List
- func (l *List[D]) AddHead(data D) *List[D]
- func (l *List[D]) AddTail(data D) *List[D]
- func (l *List[D]) DeleteAt(index int) (D, error)
- func (l *List[D]) Each(eachFunc func(data D))
- func (l *List[D]) Filter(filterFunc func(data D) bool) *List[D]
- func (l *List[D]) Find(data D) (int, error)
- func (l *List[D]) HasMember(data D) bool
- func (l *List[D]) InsertAt(index int, data D) error
- func (l *List[D]) Map(mapFunc func(data D) D) *List[D]
- func (l *List[D]) PopHead() (D, error)
- func (l *List[D]) PopTail() (D, error)
- func (l *List[D]) ReadAt(index int) (D, error)
- func (l *List[D]) ToSlice() []D
- type Tree
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type List ¶
type List[D comparable] struct { // contains filtered or unexported fields }
List implements a double linked list using generic type D with should be a type that is comparable
func NewList ¶
func NewList[D comparable]() *List[D]
NewList returns a new list of type D, which is a type that should be comparable.
Example:
// Creates a new list of type string list := NewList[string] // Creates a new list of type int list := NewList[int]
func NewListFromSlice ¶
func NewListFromSlice[D comparable](slice []D) *List[D]
NewListFromSlice returns a new list from slice. The newly created list will copy over the elements from the given slice and share its type Example:
// Creates a new list of type string list := NewListFromSlice([]string{"a", "b", "c"})
func (*List[D]) AddHead ¶
AddHead adds a new element to head (beginning) of the List
Performance: O(1) (constant)
func (*List[D]) AddTail ¶
AddTail adds a new element to tail (end) of the List
Performance: O(1) (constant)
func (*List[D]) DeleteAt ¶
DeleteAt deletes the element from the list at the given index and returns the data stored for that element. If the given index is higher than the current length of the list ErrIndexOutOfBounds is returned
Performance (worst case): O(n) (linear)
func (*List[D]) Each ¶
func (l *List[D]) Each(eachFunc func(data D))
Each invokes eachFunc on every element in the list
func (*List[D]) Filter ¶
Filter returns a list with only the elements for which filterFunc returns true
func (*List[D]) Find ¶
Find returns the index for data of type D if present in List, or returns ErrNotFound if the given data could not be found in the list.
Performance (worst case): O(n) (linear)
func (*List[D]) HasMember ¶
HasMember returns a bool indicating whether data is in the List
Performance (worst case): O(n) (linear)
func (*List[D]) InsertAt ¶
InxertAt inserts a new element to the given index. If the given index is higher than the current length of the list ErrIndexOutOfBounds is returned
Performance (worst case): O(n) (linear)
func (*List[D]) Map ¶
Map applies mapFunc on every element in the list, and returns the list with the updated elements
func (*List[D]) PopHead ¶
PopHead removes the first element of the list and returns it. If the list is empty ErrEmpty is returned
Performance: O(1) (constant)
func (*List[D]) PopTail ¶
PopTail removes the last element of the list and returns it. If the list is empty ErrEmpty is returned
Performance: O(1) (constant)