Documentation
¶
Index ¶
- type List
- func (l *List[O]) Append(store *Store[O], attach List[O])
- func (l *List[O]) Filter(store *Store[O], pred func(o *O) bool)
- func (l *List[O]) IsEmpty() bool
- func (l *List[O]) Len(store *Store[O]) int
- func (l *List[O]) PeakHead(store *Store[O]) *O
- func (l *List[O]) PeakTail(store *Store[O]) *O
- func (l *List[O]) PushHead(store *Store[O]) *O
- func (l *List[O]) PushTail(store *Store[O]) *O
- func (l *List[O]) RemoveHead(store *Store[O])
- func (l *List[O]) RemoveTail(store *Store[O])
- func (l *List[O]) Survey(store *Store[O], fun func(o *O) bool) bool
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
A List is simply a Reference to a node
func (*List[O]) Append ¶
Adds the nodes in attach to l. After this method is called attach should no longer be used.
func (*List[O]) Filter ¶
This method iterates over every node in the list. For each node the function is called with a pointer to the embedded data for that node. It is possible, although a bit unusual, to mutate the embedded data in the list via these pointers. For each function call, if the return value is true then the node will be removed from the list. Removing an element from a list causes the node to be freed and its memory returned to the store.
The embedded data pointed to in each function call is owned by the list. Client code probably should not retain pointers outside the scope of the Survey method call. It is always acceptable to retain a copy of the embedded data value.
func (*List[O]) IsEmpty ¶
Indicates whether this list is empty. This function has two advantages over Len, if you only care in whether a list is empty or not.
1: Because it does not actually look at any list data, no *Store argument is needed. 2: It is fast, because it doesn't need to iterate over the list
func (*List[O]) PushHead ¶
Pushes a single new node into the first position of an existing list. The list may be empty. The list node is allocated internally and a pointer to the embedded data is returned. The embedded data can then be mutated via this pointer.
func (*List[O]) PushTail ¶
Pushes a single new node into the last position of an existing list. The list may be empty. The list node is allocated internally and a pointer to the embedded data is returned. The embedded data can then be mutated via this pointer.
func (*List[O]) RemoveHead ¶
func (*List[O]) RemoveTail ¶
func (*List[O]) Survey ¶
This method iterates over every node in the list. For each node the function is called with a pointer to the embedded data for that node. It is possible, and idiomatic, to mutate the embedded data in the list via these pointers.
The embedded data pointed to in each function call is owned by the list. Client code probably should not retain pointers outside the scope of the Survey method call. It is always acceptable to retain a copy of the embedded data value.
type Store ¶
type Store[O any] struct { // contains filtered or unexported fields }
The store for linked lists. It is used to create a new list, but must also be passed into any method which operates on linkedlists.