vector

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 3 Imported by: 0

README

This is an concurrent-queue and concurrent-stack lib for the go.

Go Reference license GoCover size


Getting Started

Pull in the dependency

go get github.com/boobusy/vector

Add the import to your project

import (
    "github.com/boobusy/vector"
)

Simple

func main() {
	for i := 0; i < 100; i++ {
		vector.Push(i)
	}

	fmt.Println(vector.IsEmpty(),vector.Len(),vector.Cap())
	fmt.Println(vector.Items())

	for !vector.IsEmpty() {
		fmt.Println(vector.PopBack()) // or fmt.Println(vector.PopFront())
	}

}

thread-safe

func main() {

    var queue *vector.Type = vector.New(10000)
	//queue := vector.New(10000)

	// auto clean
	queue.UsePurge(1<<20, 100 * time.Millisecond)

	w := sync.WaitGroup{}
	for i := 0; i < 100; i++ {
		w.Add(1)
		go func() {
			defer w.Done()
			for k := 0; k < 1000; k++ {
				task := &Task{
					Id: k,
				}
				queue.Push(task)
			}
		}()
	}

	w.Wait()
	fmt.Println(queue.IsEmpty(), queue.Len(), queue.Cap())

	var val vector.Val
	for !queue.IsEmpty() {
        val = queue.PopBack()
		fmt.Println(val.(*Task).Id) // or fmt.Println(vector.PopFront())
	}

}

Examples

author

问题或者建议联系作者:十二楼五城

boobusy

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cap

func Cap() int

Cap returns the capacity of items.

func IsEmpty

func IsEmpty() bool

func Items

func Items() []any

Items returns the items.

func Len

func Len() int

Len returns the number of items.

func PopBack

func PopBack() any

PopBack returns the last val of items.

func PopFront

func PopFront() any

PopFront returns the first val of items.

func Push

func Push(item any)

Push inserts a new item e with value v at the back of items.

func Remake

func Remake(size int)

Remake items size

Types

type Type

type Type = vector

func New

func New(size int) *Type

func UsePurge

func UsePurge(maxSize int, interval time.Duration) *Type

type Val

type Val = any

Jump to

Keyboard shortcuts

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