al

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: BSD-3-Clause Imports: 1 Imported by: 0

README

Gosl. utl/al. Algorithms (classic)

go.dev reference

More information is available in the documentation of this package.

This package implements some classic algorithms and structures, for instance:

  • Queue
  • Stack
  • ..

TODO

  • Add benchmarks

Documentation

Overview

Package al implements classical algorithms such as Queue, Stack and others

Package al implements classical algorithms such as Queue, Stack and others

Package al implements classical algorithms such as Queue, Stack and others

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float64Comparator

func Float64Comparator(a, b float64) int

Float64Comparator compares float64s

func Float64RecQuickSort

func Float64RecQuickSort(A []float64, compare func(a, b float64) int)

Float64RecQuickSort is a Recursive (Naive) implementation of the quicksort algorithm (Hoare version)

compare -- returns:  +1 if a > b
                      0 if a == b
                     -1 if a < b

Note: recursive version

func Float64RecQuickSortNonOpt

func Float64RecQuickSortNonOpt(A []float64, compare func(a, b float64) int)

Float64RecQuickSortNonOpt is the non-optimal version of Float64RecQuickSort

func IntComparator

func IntComparator(a, b int) int

IntComparator compares ints

func IntRecQuickSort

func IntRecQuickSort(A []int, compare func(a, b int) int)

IntRecQuickSort is a Recursive (Naive) implementation of the quicksort algorithm (Hoare version)

compare -- returns:  +1 if a > b
                      0 if a == b
                     -1 if a < b

Note: recursive version

func IntRecQuickSortNonOpt

func IntRecQuickSortNonOpt(A []int, compare func(a, b int) int)

IntRecQuickSortNonOpt is the non-optimal version of IntRecQuickSort

func StringComparator

func StringComparator(a, b string) int

StringComparator compares strings lexicographically (lexicographical order)

func StringRecQuickSort

func StringRecQuickSort(A []string, compare func(a, b string) int)

StringRecQuickSort is a Recursive (Naive) implementation of the quicksort algorithm (Hoare version)

compare -- returns:  +1 if a > b
                      0 if a == b
                     -1 if a < b

Note: recursive version

func StringRecQuickSortNonOpt

func StringRecQuickSortNonOpt(A []string, compare func(a, b string) int)

StringRecQuickSortNonOpt is the non-optimal version of StringRecQuickSort

Types

type Float64LinkedList

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

Float64LinkedList defines Doubly Linked List

func NewFloat64LinkedList

func NewFloat64LinkedList() (o *Float64LinkedList)

NewFloat64LinkedList returns a new Doubly Linked List object

func (*Float64LinkedList) Find

func (o *Float64LinkedList) Find(condition func(node *Float64LinkedNode) bool) (found *Float64LinkedNode)

Find finds a node by traversing the list and comparing a to b

func (*Float64LinkedList) Insert

func (o *Float64LinkedList) Insert(data float64) (newNode *Float64LinkedNode)

Insert inserts data just after root and returns the inserted node

func (*Float64LinkedList) Remove

func (o *Float64LinkedList) Remove(node *Float64LinkedNode)

Remove removes node from Doubly Linked List

func (*Float64LinkedList) String

func (o *Float64LinkedList) String() (l string)

String returns a string representation of this list, after traversing all nodes

func (*Float64LinkedList) Traverse

func (o *Float64LinkedList) Traverse(action func(node *Float64LinkedNode) (stop bool))

Traverse traverses the Doubly Linked List and executes action(node) Note action(node) may never be called if there aren't any nodes in the list

type Float64LinkedNode

type Float64LinkedNode struct {
	Data *float64
	// contains filtered or unexported fields
}

Float64LinkedNode defines a node in a Doubly Linked List

type Float64Queue

type Float64Queue struct {
	Debug bool // debug flag
	// contains filtered or unexported fields
}

Float64Queue implements a FIFO queue, a sequence where the first inserted will be the first removed. Think of arriving people at the Bank or DMV...

func NewFloat64Queue

func NewFloat64Queue(guessedBufferSize int) (o *Float64Queue)

NewFloat64Queue returns a new object

func (*Float64Queue) Back

func (o *Float64Queue) Back() *float64

Back returns the member @ back (unlucky guy/girl...) or nil if empty. It is always the last item in the data array

func (*Float64Queue) Front

func (o *Float64Queue) Front() *float64

Front returns the member @ front of queue (close to the DMV window...) or nil if empty

func (*Float64Queue) In

func (o *Float64Queue) In(member float64)

In receives a new member arrival TODO: implement use of different grow rates

func (*Float64Queue) Nmembers

func (o *Float64Queue) Nmembers() int

Nmembers returns the length of queue; i.e. the number of members

func (*Float64Queue) Out

func (o *Float64Queue) Out() (member *float64)

Out removes the member @ front and returns a pointer to him/her TODO: implement memory recovery

func (*Float64Queue) String

func (o *Float64Queue) String() (l string)

String returns the string representation of this object

type IntLinkedList

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

IntLinkedList defines Doubly Linked List

func NewIntLinkedList

func NewIntLinkedList() (o *IntLinkedList)

NewIntLinkedList returns a new Doubly Linked List object

func (*IntLinkedList) Find

func (o *IntLinkedList) Find(condition func(node *IntLinkedNode) bool) (found *IntLinkedNode)

Find finds a node by traversing the list and comparing a to b

func (*IntLinkedList) Insert

func (o *IntLinkedList) Insert(data int) (newNode *IntLinkedNode)

Insert inserts data just after root and returns the inserted node

func (*IntLinkedList) Remove

func (o *IntLinkedList) Remove(node *IntLinkedNode)

Remove removes node from Doubly Linked List

func (*IntLinkedList) String

func (o *IntLinkedList) String() (l string)

String returns a string representation of this list, after traversing all nodes

func (*IntLinkedList) Traverse

func (o *IntLinkedList) Traverse(action func(node *IntLinkedNode) (stop bool))

Traverse traverses the Doubly Linked List and executes action(node) Note action(node) may never be called if there aren't any nodes in the list

type IntLinkedNode

type IntLinkedNode struct {
	Data *int
	// contains filtered or unexported fields
}

IntLinkedNode defines a node in a Doubly Linked List

type IntQueue

type IntQueue struct {
	Debug bool // debug flag
	// contains filtered or unexported fields
}

IntQueue implements a FIFO queue, a sequence where the first inserted will be the first removed. Think of arriving people at the Bank or DMV...

func NewIntQueue

func NewIntQueue(guessedBufferSize int) (o *IntQueue)

NewIntQueue returns a new object

func (*IntQueue) Back

func (o *IntQueue) Back() *int

Back returns the member @ back (unlucky guy/girl...) or nil if empty. It is always the last item in the data array

func (*IntQueue) Front

func (o *IntQueue) Front() *int

Front returns the member @ front of queue (close to the DMV window...) or nil if empty

func (*IntQueue) In

func (o *IntQueue) In(member int)

In receives a new member arrival TODO: implement use of different grow rates

func (*IntQueue) Nmembers

func (o *IntQueue) Nmembers() int

Nmembers returns the length of queue; i.e. the number of members

func (*IntQueue) Out

func (o *IntQueue) Out() (member *int)

Out removes the member @ front and returns a pointer to him/her TODO: implement memory recovery

func (*IntQueue) String

func (o *IntQueue) String() (l string)

String returns the string representation of this object

type StringLinkedList

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

StringLinkedList defines Doubly Linked List

func NewStringLinkedList

func NewStringLinkedList() (o *StringLinkedList)

NewStringLinkedList returns a new Doubly Linked List object

func (*StringLinkedList) Find

func (o *StringLinkedList) Find(condition func(node *StringLinkedNode) bool) (found *StringLinkedNode)

Find finds a node by traversing the list and comparing a to b

func (*StringLinkedList) Insert

func (o *StringLinkedList) Insert(data string) (newNode *StringLinkedNode)

Insert inserts data just after root and returns the inserted node

func (*StringLinkedList) Remove

func (o *StringLinkedList) Remove(node *StringLinkedNode)

Remove removes node from Doubly Linked List

func (*StringLinkedList) String

func (o *StringLinkedList) String() (l string)

String returns a string representation of this list, after traversing all nodes

func (*StringLinkedList) Traverse

func (o *StringLinkedList) Traverse(action func(node *StringLinkedNode) (stop bool))

Traverse traverses the Doubly Linked List and executes action(node) Note action(node) may never be called if there aren't any nodes in the list

type StringLinkedNode

type StringLinkedNode struct {
	Data *string
	// contains filtered or unexported fields
}

StringLinkedNode defines a node in a Doubly Linked List

type StringQueue

type StringQueue struct {
	Debug bool // debug flag
	// contains filtered or unexported fields
}

StringQueue implements a FIFO queue, a sequence where the first inserted will be the first removed. Think of arriving people at the Bank or DMV...

func NewStringQueue

func NewStringQueue(guessedBufferSize int) (o *StringQueue)

NewStringQueue returns a new object

func (*StringQueue) Back

func (o *StringQueue) Back() *string

Back returns the member @ back (unlucky guy/girl...) or nil if empty. It is always the last item in the data array

func (*StringQueue) Front

func (o *StringQueue) Front() *string

Front returns the member @ front of queue (close to the DMV window...) or nil if empty

func (*StringQueue) In

func (o *StringQueue) In(member string)

In receives a new member arrival TODO: implement use of different grow rates

func (*StringQueue) Nmembers

func (o *StringQueue) Nmembers() int

Nmembers returns the length of queue; i.e. the number of members

func (*StringQueue) Out

func (o *StringQueue) Out() (member *string)

Out removes the member @ front and returns a pointer to him/her TODO: implement memory recovery

func (*StringQueue) String

func (o *StringQueue) String() (l string)

String returns the string representation of this object

Jump to

Keyboard shortcuts

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