common

package
v0.0.0-...-46d524f Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(a int) int

Abs returns the absolute value for a given integer.

func AbsDiff

func AbsDiff(a, b int) int

AbsDiff returns the absolute value of the difference between two integers.

func ChanToSlice

func ChanToSlice(ch chan int) []int

ChanToSlice pushes values from a channel to a slice.

func Contain

func Contain(s []int, target int) bool

Contain checks if the target is in a slice.

func ContainString

func ContainString(s []string, target string) bool

ContainString checks if the target is in a slice.

func Equal

func Equal(t *testing.T, expected, result interface{})

Equal checks if two input are deeply equal.

func IsLessThan1Apart

func IsLessThan1Apart(a, b int) bool

IsLessThan1Apart checks if two integers are less or equal than 1 apart.

func IsMoreThan1Apart

func IsMoreThan1Apart(a, b int) bool

IsMoreThan1Apart checks if two integers are more than 1 apart.

func LinkedListToSlice

func LinkedListToSlice(node *ListNode) []int

LinkedListToSlice converts a linked list into an array of integer.

func Log

func Log(m map[string]interface{})

Log prints out the map of logging context and value.

func Max

func Max(nums ...int) int

Max returns max from a list of integers.

func Mimax

func Mimax(nums ...int) (int, int)

Mimax returns min and max from a list of integers.

func Min

func Min(nums ...int) int

Min returns min from a list of integers.

func Random

func Random(min, max int) int

Random rertuns a random number over a range

func SumInt

func SumInt(nums []int) int

SumInt returns the sum of all integers in a given slice.

func Swap

func Swap(v interface{}, i, j int)

Swap two array values given their indices.

func SwapInt

func SwapInt(a []int, i, j int)

SwapInt two array values given their indices.

func SwapString

func SwapString(a []string, i, j int)

SwapString two array values given their indices.

Types

type List

type List struct {
	// contains filtered or unexported fields
}

List implements a linked list.

func NewList

func NewList() *List

NewList returns a new list.

func (*List) Back

func (l *List) Back() interface{}

Back returns the last element of the list.

func (*List) Front

func (l *List) Front() interface{}

Front returns the first element of the list.

func (*List) InsertAfter

func (l *List) InsertAfter(v, mark interface{})

InsertAfter inserts an element after another.

func (*List) InsertBefore

func (l *List) InsertBefore(v, mark interface{})

InsertBefore inserts an element before another.

func (*List) Len

func (l *List) Len() interface{}

Len returns the number of elements of the list.

func (*List) MoveAfter

func (l *List) MoveAfter(v, mark interface{})

MoveAfter moves an element after another.

func (*List) MoveBack

func (l *List) MoveBack(v interface{})

MoveBack moves an element to the back of the list.

func (*List) MoveBefore

func (l *List) MoveBefore(v, mark interface{})

MoveBefore moves an element before another.

func (*List) MoveFront

func (l *List) MoveFront(v interface{})

MoveFront moves an element to the front of the list.

func (*List) PushBack

func (l *List) PushBack(v interface{}) interface{}

PushBack inserts an element at the back of the list.

func (*List) PushFront

func (l *List) PushFront(v interface{}) interface{}

PushFront inserts an element at the front of the list.

func (*List) RemoveBack

func (l *List) RemoveBack() interface{}

RemoveBack removes an element at the back of the list.

func (*List) RemoveFront

func (l *List) RemoveFront() interface{}

RemoveFront removes an element at the front of the list.

func (*List) Slice

func (l *List) Slice() []interface{}

Slice returns a slice of all elements in the list.

type ListNode

type ListNode struct {
	Value int
	Next  *ListNode
}

ListNode represents a node in a linked list.

func NewListNode

func NewListNode(v int) *ListNode

NewListNode returns a new list node.

func (*ListNode) AddNext

func (l *ListNode) AddNext(v int)

AddNext adds a next node to the end of list.

type MaxHeap

type MaxHeap struct {
	// contains filtered or unexported fields
}

MaxHeap represents a max heap data structure.

func NewMaxHeap

func NewMaxHeap() *MaxHeap

NewMaxHeap returns a new max heap.

func (*MaxHeap) Len

func (h *MaxHeap) Len() int

Len returns the number of items in the heap.

func (*MaxHeap) Peek

func (h *MaxHeap) Peek() int

Peek returns the maximum item in the heap.

func (*MaxHeap) Pop

func (h *MaxHeap) Pop() int

Pop returns the root node after removing it from the heap.

func (*MaxHeap) Push

func (h *MaxHeap) Push(x int)

Push adds a new node to the heap.

type MinHeap

type MinHeap struct {
	// contains filtered or unexported fields
}

MinHeap represents a min heap data structure.

func NewMinHeap

func NewMinHeap() *MinHeap

NewMinHeap returns a new min heap.

func (*MinHeap) Len

func (h *MinHeap) Len() int

Len returns the number of items in the heap.

func (*MinHeap) Peek

func (h *MinHeap) Peek() int

Peek returns the minimum item in the heap.

func (*MinHeap) Pop

func (h *MinHeap) Pop() int

Pop returns the root node after removing it from the heap.

func (*MinHeap) Push

func (h *MinHeap) Push(x int)

Push adds a new node to the heap.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue implements a queue data structure.

func NewQueue

func NewQueue() *Queue

NewQueue initializes and returns a new queue.

func (*Queue) Back

func (q *Queue) Back() interface{}

Back returns the element in the back of the queue.

func (*Queue) Empty

func (q *Queue) Empty() bool

Empty checks if the queue is empty.

func (*Queue) Front

func (q *Queue) Front() interface{}

Front returns the element in the front of the queue.

func (*Queue) Pop

func (q *Queue) Pop() interface{}

Pop removes and returns the element in the front of the queue.

func (*Queue) Print

func (q *Queue) Print()

Print prints all the elements in the queue.

func (*Queue) Push

func (q *Queue) Push(v interface{})

Push adds a element in the back of the queue.

func (*Queue) Size

func (q *Queue) Size() int

Size returns the total number of elements in the queue.

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack implements a stack data structure.

func NewStack

func NewStack() *Stack

NewStack initializes and returns a new stack.

func (*Stack) Empty

func (q *Stack) Empty() bool

Empty checks if the stack is empty.

func (*Stack) Pop

func (q *Stack) Pop() interface{}

Pop removes and returns the element on top of the stack.

func (*Stack) Print

func (q *Stack) Print()

Print prints all elements in the stack.

func (*Stack) Push

func (q *Stack) Push(v interface{})

Push adds the element on top of the stack.

func (*Stack) Size

func (q *Stack) Size() int

Size returns the total number of elements in the stack.

func (*Stack) Top

func (q *Stack) Top() interface{}

Top returns the element on top of the stack.

type TreeNode

type TreeNode struct {
	Left  *TreeNode
	Value int
	Right *TreeNode
}

TreeNode represents a node in a binary tree.

func NewTreeNode

func NewTreeNode(v int) *TreeNode

NewTreeNode returns a new TreeNode.

Jump to

Keyboard shortcuts

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