goal

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

README

goal

Package provides a fast queue, deque, stack and binary tree containers based on generics to handle multiple types.

Prerequisites

A Go 1.18 or later installed.

Containers

Containers using generics to handle multiple types.

  • Stack

Stack container implementation.

  • Queue

Queue container implementation.

  • Deque

Double-ended queue container implementation.

  • Binary tree

Binary tree data structure implementation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deque

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

Deque represents a instance of the queue data container.

func MakeDeque

func MakeDeque[T any]() *Deque[T]

MakeDeque constructs and return a new Deque.

func (*Deque[T]) Clear

func (dq *Deque[T]) Clear()

Clear clears the container. After this call, Len() returns zero.

func (*Deque[T]) Len

func (dq *Deque[T]) Len() int

Len returns the number of elements.

func (*Deque[T]) PopBack

func (dq *Deque[T]) PopBack() (T, bool)

PopBack returns the last element

func (*Deque[T]) PopFront

func (dq *Deque[T]) PopFront() (T, bool)

PopFront returns the first element

func (*Deque[T]) PushBack

func (dq *Deque[T]) PushBack(v T)

PushBack adds an element to the end

func (*Deque[T]) PushFront

func (dq *Deque[T]) PushFront(v T)

PushFront inserts an element to the beginning

type Queue

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

Queue represents a instance of the queue data container.

func MakeQueue

func MakeQueue[T any](capacity int) *Queue[T]

MakeQueue constructs and return a new Queue.

func (*Queue[T]) Cap

func (q *Queue[T]) Cap() int

Cap returns the capacity of container.

func (*Queue[T]) Clear

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

Clear clears the container. After this call, Len() returns zero.

func (*Queue[T]) Erase

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

Erase erases all unused elements.

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

Len returns the number of elements.

func (*Queue[T]) Pop

func (q *Queue[T]) Pop() (T, bool)

Pop return the first element.

func (*Queue[T]) Push

func (q *Queue[T]) Push(v T)

Push inserts element at the end.

type Stack

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

Stack represents a instance of the stack data container.

func MakeStack

func MakeStack[T any](capacity int) *Stack[T]

MakeStack constructs and return a new Stack.

func (*Stack[T]) Cap

func (s *Stack[T]) Cap() int

Cap returns the capacity of container.

func (*Stack[T]) Clear

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

Clear clears the container. After this call, Len() returns zero.

func (*Stack[T]) Erase

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

Erase erases all unused elements.

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

Len returns the number of elements.

func (*Stack[T]) Pop

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

Pop return the top element.

func (*Stack[T]) Push

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

Push inserts element at the top.

type Tree added in v0.2.0

type Tree[K constraints.Ordered, V any] struct {
	Key   K
	Value V
	// contains filtered or unexported fields
}

func MakeTree added in v0.2.1

func MakeTree[K constraints.Ordered, V any](k K, v V) (*Tree[K, V], error)

MakeTree constructs and return a new Binary Tree.

func (*Tree[K, V]) Find added in v0.2.0

func (t *Tree[K, V]) Find(key K) (V, bool)

Finds an element in the tree by key

func (*Tree[K, V]) Insert added in v0.2.0

func (t *Tree[K, V]) Insert(key K, value V)

Inserts an element into tree

func (*Tree[K, V]) Remove added in v0.2.0

func (t *Tree[K, V]) Remove(key K) bool

Removes an element from the tree by key

Jump to

Keyboard shortcuts

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