ts

package module
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: MIT Imports: 1 Imported by: 1

README

A package for common thread safe data structures

GitHub tag (latest SemVer pre-release) GitHub go.mod Go version GitHub Workflow Status Go Report Card PkgGoDev

Introduction

  • Currently supports linked lists and slices
  • No dependencies outside the standard library

Example

package main

import (
	"fmt"

	ts "github.com/2pisoftware/gofor-little-ts"
)

func main() {
    list := ts.LinkedList{}
    list.Push("Some string")

    item := list.GetTail()
    fmt.Println(item)

    item = list.Pop()
    fmt.Println(item)

    slice := ts.Slice{}

    slice.Add(1, 2, 3)
    fmt.Println(slice.GetElements())

    slice.Remove(1, 2, 3)
    fmt.Println(slice.GetElements())
}

Testing

Run go test -v -race ./... in the root directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LinkedList

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

LinkedList is a thread safe first in first out (FIFO) list.

func (*LinkedList) GetTail

func (l *LinkedList) GetTail() interface{}

GetTail returns a copy of the value in the last item of the LinkedList.

func (*LinkedList) IsEmpty

func (l *LinkedList) IsEmpty() bool

IsEmpty checks if the LinkedList is empty.

func (*LinkedList) Pop

func (l *LinkedList) Pop() interface{}

Pop pops the first item from the start of the LinkedList.

func (*LinkedList) Push

func (l *LinkedList) Push(value interface{})

Push pushes a new item to the end of the LinkedList.

type LinkedListItem

type LinkedListItem struct {
	Value interface{}
	// contains filtered or unexported fields
}

LinkedListItem wraps a value and a reference to the next LinkedListItem.

type Slice

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

Slice wraps a standard slice and a sync.RWMutex.

func (*Slice) Add

func (s *Slice) Add(elements ...interface{})

Add adds the passed elements to the underlying slice.

func (*Slice) GetElement

func (s *Slice) GetElement(index int) interface{}

GetElement returns the element from the underlying slice at the passed index.

func (*Slice) GetElements

func (s *Slice) GetElements() []interface{}

GetElements returns the underlying slice.

func (*Slice) Length

func (s *Slice) Length() int

Length returns the length of the underlying slice.

func (*Slice) Remove

func (s *Slice) Remove(elements ...interface{})

Remove removes the passed elements from the underlying slice.

Jump to

Keyboard shortcuts

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