linkedlist

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List[O any] offheap.RefObject[node[O]]

A List is simply a Reference to a node

func (*List[O]) Append

func (l *List[O]) Append(store *Store[O], attach List[O])

Adds the nodes in attach to l. After this method is called attach should no longer be used.

func (*List[O]) Filter

func (l *List[O]) Filter(store *Store[O], pred func(o *O) bool)

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

func (l *List[O]) IsEmpty() bool

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]) Len

func (l *List[O]) Len(store *Store[O]) int

Consider a way to do this which doesn't need to iterate over the whole list

func (*List[O]) PeakHead

func (l *List[O]) PeakHead(store *Store[O]) *O

func (*List[O]) PeakTail

func (l *List[O]) PeakTail(store *Store[O]) *O

func (*List[O]) PushHead

func (l *List[O]) PushHead(store *Store[O]) *O

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

func (l *List[O]) PushTail(store *Store[O]) *O

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 (l *List[O]) RemoveHead(store *Store[O])

func (*List[O]) RemoveTail

func (l *List[O]) RemoveTail(store *Store[O])

func (*List[O]) Survey

func (l *List[O]) Survey(store *Store[O], fun func(o *O) bool) bool

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.

func New

func New[O any]() *Store[O]

Creates a new Store.

func (*Store[O]) NewList

func (s *Store[O]) NewList() List[O]

Creates a new empty list l.getReference().IsNil() will return true This method isn't strictly necessary. The zero value of a List[O] behaves exactly the same as one created by a Store[O]. However we include the method because it makes code easier to follow.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL