lstructs

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: BSD-3-Clause Imports: 1 Imported by: 0

README

Lam-Structures

This is a useful test to publish to the golang packages and allows users to pull from here

Please refer to all of the functions and data structures in https://pkg.go.dev/github.com/edelille/lstructs

How to use

  1. Import via "github.com/edelille/lstructs" on top of the file
  2. Grab it using $ go get github.com/edelille/lstructs
  3. Update using $ go mod tidy

Example Code

package main

import (
    "fmt"

    ls "github.com/edelille/lstructs"
)

func main() {
    // Initialize the data structure
    stack := ls.NewStack[int]()

    // Push onto the Stack!
    stack.Push(5)

    // Peek on top of the Stack!
    fmt.Println(stack.Peek())   // Should print 5

    // Pop off the top!
    fmt.Println(stack.Pop())   // Should print 5, and removes 5 off of stack

    fmt.Println(stack.Size())   // Should print 0
    fmt.Println(stack.IsEmpty())   // Should print true
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equals added in v0.0.7

func Equals[T comparable](x, y T) bool

func Less added in v0.0.7

func Less[T constraints.Ordered](x, y T) bool

func Swap added in v0.0.7

func Swap[T any](arr []T, i, j int)

Types

type BST added in v0.0.7

type BST[T comparable] struct {
	Length int
	Head   *BSTNode[T]
	Less   LessFn[T]
}

func NewBST added in v0.0.7

func NewBST[T comparable](less LessFn[T]) *BST[T]

func (*BST[T]) InorderTraversal added in v0.0.7

func (b *BST[T]) InorderTraversal() []T

func (*BST[T]) Insert added in v0.0.7

func (b *BST[T]) Insert(x T)

func (*BST[T]) PostorderTraversal added in v0.0.7

func (b *BST[T]) PostorderTraversal() []T

func (*BST[T]) PreorderTraversal added in v0.0.7

func (b *BST[T]) PreorderTraversal() []T

func (*BST[T]) Rebalance added in v0.0.7

func (b *BST[T]) Rebalance()

func (*BST[T]) Remove added in v0.0.7

func (b *BST[T]) Remove(x T)

func (*BST[T]) Search added in v0.0.7

func (b *BST[T]) Search(x T) bool

func (*BST[T]) Size added in v0.0.7

func (b *BST[T]) Size() int

type BSTNode added in v0.0.7

type BSTNode[T comparable] struct {
	Val   T
	Left  *BSTNode[T]
	Right *BSTNode[T]
}

type Deque added in v0.0.5

type Deque[T any] struct {
	Length int
	Data   []T
}

func NewDeque added in v0.0.5

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

func (*Deque[T]) IsEmpty added in v0.0.5

func (d *Deque[T]) IsEmpty() bool

func (*Deque[T]) PeekLeft added in v0.0.5

func (d *Deque[T]) PeekLeft() T

func (*Deque[T]) PeekRight added in v0.0.5

func (d *Deque[T]) PeekRight() T

func (*Deque[T]) PopLeft added in v0.0.5

func (d *Deque[T]) PopLeft() T

func (*Deque[T]) PopRight added in v0.0.5

func (d *Deque[T]) PopRight() T

func (*Deque[T]) PushLeft added in v0.0.5

func (d *Deque[T]) PushLeft(x T)

func (*Deque[T]) PushRight added in v0.0.5

func (d *Deque[T]) PushRight(x T)

func (*Deque[T]) Size added in v0.0.5

func (d *Deque[T]) Size() int

type EqualsFn added in v0.0.7

type EqualsFn[T comparable] func(x, y T) bool

type Heap added in v0.0.7

type Heap[T comparable] struct {
	Length int
	Data   []T
	// contains filtered or unexported fields
}

func NewHeap added in v0.0.7

func NewHeap[T comparable](less LessFn[T]) *Heap[T]

func (*Heap[T]) Delete added in v0.0.7

func (h *Heap[T]) Delete(x T) bool

The delete function will return True on successful deletion

func (*Heap[T]) Insert added in v0.0.7

func (h *Heap[T]) Insert(x T)

func (*Heap[T]) IsEmpty added in v0.0.7

func (h *Heap[T]) IsEmpty() bool

func (*Heap[T]) Peek added in v0.0.7

func (h *Heap[T]) Peek() T

func (*Heap[T]) Pop added in v0.0.7

func (h *Heap[T]) Pop() T

func (*Heap[T]) Size added in v0.0.7

func (h *Heap[T]) Size() int

type LessFn added in v0.0.7

type LessFn[T comparable] func(x, y T) bool

type Queue

type Queue[T any] struct {
	Length int
	Data   []T
}

func NewQueue

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

func (*Queue[T]) Dequeue

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

func (*Queue[T]) Enqueue

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

func (*Queue[T]) IsEmpty added in v0.0.5

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

func (*Queue[T]) Peek

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

func (*Queue[T]) Size

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

type Set added in v0.0.5

type Set[T comparable] struct {
	Length int
	Data   map[T]interface{}
}

func NewSet added in v0.0.5

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

func (*Set[T]) Add added in v0.0.5

func (s *Set[T]) Add(x T)

func (*Set[T]) Clear added in v0.0.5

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

func (*Set[T]) Has added in v0.0.5

func (s *Set[T]) Has(x T) bool

func (*Set[T]) IsEmpty added in v0.0.5

func (s *Set[T]) IsEmpty() bool

func (*Set[T]) Remove added in v0.0.5

func (s *Set[T]) Remove(x T)

func (*Set[T]) Size added in v0.0.5

func (s *Set[T]) Size() int

type Stack

type Stack[T any] struct {
	Length int
	Data   []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

func (*Stack[T]) Pop

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

func (*Stack[T]) Push

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

func (*Stack[T]) Size

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

Jump to

Keyboard shortcuts

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