README
¶
Linked List Library
Welcome to the Linked List Library! This comprehensive library offers a powerful collection of functions and methods with the ability to easily generate and efficiently manage linked lists of any data type using go generics.
Table of Contents
- Linked List Library
Install
Use go get -u to install the latest version of this package:
go get -u github.com/brianlewyn/go-linked-list/v3
What's a Linked List?
A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. Instead, the elements in a linked list are linked using pointers.
Besides, it's also a dynamic data structure, it occupies memory only for the stored data.
In fact, the principal benefit of a linked list over a conventional array is that the list elements can easily be inserted or removed without reallocation of any other elements.
Doubly Linked List
A doubly linked list or a two-way linked list is a more complex type of linked list that contains a pointer to the next as well as the previous node in sequence. This would enable us to traverse the list in the backward direction as well.
Types of Double Linked List Methods
Note for Users of the Library
-
Always ensure the existence of nodes or lists passed as parameters. Use 'node != nil' and 'list != nil' to verify their presence. Neglecting this step may lead to errors.
-
Use 'init', 'push' and 'connect' methods exclusively for adding new nodes.
-
Use 'push' methods to add additional lists.
-
Check for null when working with nodes returned by methods.
-
Returned lists are guaranteed to exist. Empty lists indicate method errors.
-
Nodes should belong to the same list, unless explicitly stated for adding new nodes. Mixing nodes may cause errors.
-
Connect only new nodes to existing ones. Avoid connecting nodes already in the list or not belonging to it.
Follow these guidelines for a smooth and error-free experience with our library.
Note: If you have any doubts about how to use a specific method, I invite you to refer to our comprehensive test suite available at test sheet. Each test is designed to be clear and covers the important aspects of each method. Additionally, the order in which the methods are presented corresponds to the order they appear in the source code and test suite.
Instance Functions
New[T any]() *Doubly[T]
NewDoubly[T any](size int, head, tail *Node[T]) *Doubly[T]
Getting Methods
Size() int
Head() *Node[T]
Tail() *Node[T]
Node(index int) *Node[T]
NodeForwardFrom(from *Node[T], index int) *Node[T]
NodeBackwardFrom(from *Node[T], index int) *Node[T]
Front() (T, bool)
Back() (T, bool)
Data(index int) (T, bool)
NodeArray() []*Node[T]
DataArray() []T
String() string
Initialization Methods
Init()
InitNode(node *Node[T])
InitData(data T)
InitList(doubly *Doubly[T])
InitNodeArray(nodeArray []*Node[T])
InitDataArray(dataArray []T)
Pushing Methods
PushHead(node *Node[T])
PushTail(node *Node[T])
PushNode(index int, node *Node[T]) bool
PushNodeForwardFrom(from *Node[T], index int, node *Node[T]) bool
PushNodeBackwardFrom(from *Node[T], index int, node *Node[T]) bool
PushFront(data T)
PushBack(data T)
PushData(index int, data T) bool
PushFrontList(doubly *Doubly[T])
PushBackList(doubly *Doubly[T])
PushList(index int, doubly *Doubly[T]) bool
PushFrontNodeArray(nodeArray []*Node[T])
PushBackNodeArray(nodeArray []*Node[T])
PushNodeArray(index int, nodeArray []*Node[T]) bool
PushFrontDataArray(dataArray []T)
PushBackDataArray(dataArray []T)
PushDataArray(index int, dataArray []T) bool
Removing Methods
RemoveHead() bool
RemoveTail() bool
RemoveNode(node *Node[T]) bool
RemoveByData(data T) bool
RemoveByIndex(index int) bool
RemoveForwardFrom(from *Node[T], index int) bool
RemoveBackwardFrom(from *Node[T], index int) bool
RemoveByNodeRange(startNode, endNode *Node[T]) bool
RemoveByIndexRange(startIndex, endIndex int) bool
RemovetByDataRange(startData, endData T) bool
Pulling Methods
PullHead() *Node[T]
PullTail() *Node[T]
PullNode(index int) *Node[T]
PullNodeForwardFrom(from *Node[T], index int) *Node[T]
PullNodeBackwardFrom(from *Node[T], index int) *Node[T]
PullFront() (T, bool)
PullBack() (T, bool)
PullData(index int) (T, bool)
PullByNodeRange(startNode, endNode *Node[T]) *Doubly[T]
PullByIndexRange(startIndex, endIndex int) *Doubly[T]
PullByDataRange(startData, endData T) *Doubly[T]
Question Methods
IsEmpty() bool
IsIndexInRange(index int) bool
IndexOfNode(node *Node[T]) int
FirstIndexOfData(data T) int
LastIndexOfData(data T) int
ContainsNode(node *Node[T]) bool
ContainsData(data T) bool
Copying Methods
CopyByNodeRange(startNode, endNode *Node[T]) *Doubly[T]
CopyByIndexRange(startIndex, endIndex int) *Doubly[T]
CopyByDataRange(startData, endData T) *Doubly[T]
Updating methods
UpdateHead(node *Node[T])
UpdateTail(node *Node[T])
UpdateNode(got, want *Node[T])
Connection Methods
ConnectAfterHead(node *Node[T])
ConnectAfterNode(got, want *Node[T])
ConnectBeforeTail(node *Node[T])
ConnectBeforeNode(got, want *Node[T])
Node Handling Methods
Marshal(dataArray *[]T)
Unmarshal() []T
Swaping Methods
SwapHead(node *Node[T]) bool
SwapTail(node *Node[T]) bool
SwapNode(node1, node2 *Node[T]) bool
SwapNodoByIndex(index1, index2 int) bool
Reverse()
License
The Linked List Library is open-source and released under the MIT License. Feel free to use, modify, and distribute this library according to the terms of the license.
Thank you for choosing the Linked List Library. I hope it proves to be a valuable tool in your projects!