collection

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 1 Imported by: 2

README

collection

Collection is a Go library that provides various basic data structures such as queue, stack, tree, linked list, hash set, etc. The library aims to be efficient, easy to use, and highly customizable.

Installation

You can install the Collection library using the go get command:

go get github.com/STRockefeller/collection

Contributing

Contributions to the Collection library are welcome! If you have any bug reports, feature requests

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DoublyLinkedList

type DoublyLinkedList[T any] struct {
	// contains filtered or unexported fields
}

func NewDoublyLinkedList

func NewDoublyLinkedList[T any]() *DoublyLinkedList[T]

func (*DoublyLinkedList[T]) AddFirst

func (dll *DoublyLinkedList[T]) AddFirst(value T)

func (*DoublyLinkedList[T]) AddLast

func (dll *DoublyLinkedList[T]) AddLast(value T)

func (*DoublyLinkedList[T]) Clear

func (dll *DoublyLinkedList[T]) Clear()

func (*DoublyLinkedList[T]) GetSize

func (dll *DoublyLinkedList[T]) GetSize() int

func (*DoublyLinkedList[T]) Head

func (dll *DoublyLinkedList[T]) Head() *DoublyLinkedListNode[T]

func (*DoublyLinkedList[T]) IsEmpty

func (dll *DoublyLinkedList[T]) IsEmpty() bool

func (*DoublyLinkedList[T]) Remove

func (dll *DoublyLinkedList[T]) Remove(node *DoublyLinkedListNode[T]) T

will panic if given node is nil

func (*DoublyLinkedList[T]) RemoveFirst

func (dll *DoublyLinkedList[T]) RemoveFirst() T

will panic if list is empty

func (*DoublyLinkedList[T]) RemoveLast

func (dll *DoublyLinkedList[T]) RemoveLast() T

will panic if list is empty

func (*DoublyLinkedList[T]) Search

func (dll *DoublyLinkedList[T]) Search(value T) *DoublyLinkedListNode[T]

func (*DoublyLinkedList[T]) Tail

func (dll *DoublyLinkedList[T]) Tail() *DoublyLinkedListNode[T]

type DoublyLinkedListNode

type DoublyLinkedListNode[T any] struct {
	// contains filtered or unexported fields
}

func NewDoublyLinkedListNode

func NewDoublyLinkedListNode[T any](value T) *DoublyLinkedListNode[T]

func (*DoublyLinkedListNode[T]) GetNext

func (n *DoublyLinkedListNode[T]) GetNext() *DoublyLinkedListNode[T]

func (*DoublyLinkedListNode[T]) GetPrev

func (n *DoublyLinkedListNode[T]) GetPrev() *DoublyLinkedListNode[T]

func (*DoublyLinkedListNode[T]) GetValue

func (n *DoublyLinkedListNode[T]) GetValue() T

func (*DoublyLinkedListNode[T]) SetNext

func (n *DoublyLinkedListNode[T]) SetNext(node *DoublyLinkedListNode[T])

func (*DoublyLinkedListNode[T]) SetPrev

func (n *DoublyLinkedListNode[T]) SetPrev(node *DoublyLinkedListNode[T])

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue[T any]() Queue[T]

func NewQueueFromSlice

func NewQueueFromSlice[T any](items []T) Queue[T]

func (*Queue[T]) Dequeue

func (q *Queue[T]) Dequeue() T

please make sure the queue is not empty or the method will raise a panic.

func (*Queue[T]) Enqueue

func (q *Queue[T]) Enqueue(element T)

func (Queue[T]) IsEmpty

func (q Queue[T]) IsEmpty() bool

func (*Queue[T]) Peek

func (q *Queue[T]) Peek() T

please make sure the queue is not empty or the method will raise a panic.

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T comparable]() Set[T]

func (*Set[T]) Add

func (set *Set[T]) Add(item T)

func (*Set[T]) Contains

func (set *Set[T]) Contains(item T) bool

func (Set[T]) Length

func (set Set[T]) Length() int

func (*Set[T]) Remove

func (set *Set[T]) Remove(item T)

func (Set[T]) Traversal

func (set Set[T]) Traversal(delegate func(T))

type SinglyLinkedList

type SinglyLinkedList[T any] struct {
	// contains filtered or unexported fields
}

func NewSinglyLinkedList

func NewSinglyLinkedList[T any]() *SinglyLinkedList[T]

func (*SinglyLinkedList[T]) AddNode

func (l *SinglyLinkedList[T]) AddNode(node *SinglyLinkedListNode[T])

func (*SinglyLinkedList[T]) DeleteNode

func (l *SinglyLinkedList[T]) DeleteNode(node *SinglyLinkedListNode[T]) bool

func (*SinglyLinkedList[T]) Head

func (l *SinglyLinkedList[T]) Head() *SinglyLinkedListNode[T]

func (*SinglyLinkedList[T]) IsEmpty

func (l *SinglyLinkedList[T]) IsEmpty() bool

func (*SinglyLinkedList[T]) Search

func (l *SinglyLinkedList[T]) Search(value T) *SinglyLinkedListNode[T]

type SinglyLinkedListNode

type SinglyLinkedListNode[T any] struct {
	// contains filtered or unexported fields
}

func NewSinglyLinkedListNode

func NewSinglyLinkedListNode[T any](value T) *SinglyLinkedListNode[T]

func (*SinglyLinkedListNode[T]) GetNext

func (n *SinglyLinkedListNode[T]) GetNext() *SinglyLinkedListNode[T]

func (*SinglyLinkedListNode[T]) GetValue

func (n *SinglyLinkedListNode[T]) GetValue() T

func (*SinglyLinkedListNode[T]) SetNext

func (n *SinglyLinkedListNode[T]) SetNext(node *SinglyLinkedListNode[T])

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

func NewFromSlice

func NewFromSlice[T any](items []T) Stack[T]

func NewStack

func NewStack[T any]() Stack[T]

func (Stack[T]) IsEmpty

func (s Stack[T]) IsEmpty() bool

func (Stack[T]) Peek

func (s Stack[T]) Peek() T

please make sure the stack is not empty or the method will raise a panic.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

please make sure the stack is not empty or the method will raise a panic.

func (*Stack[T]) Push

func (s *Stack[T]) Push(item T)

type TreeNode

type TreeNode[T any] struct {
	Value    T
	Children []*TreeNode[T]
}

TreeNode represents a node in a generic tree.

func NewTreeNode

func NewTreeNode[T any](value T) *TreeNode[T]

NewTreeNode creates a new TreeNode with the given value.

func (*TreeNode[T]) AddChild

func (n *TreeNode[T]) AddChild(child *TreeNode[T])

AddChild adds a child node to the current node.

func (*TreeNode[T]) DepthFirstTraversal

func (n *TreeNode[T]) DepthFirstTraversal() []T

DepthFirstTraversal performs a depth-first traversal of the tree rooted at the current node and returns a slice of values.

Jump to

Keyboard shortcuts

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