queue

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2022 License: MIT Imports: 1 Imported by: 0

README

go-safequeue

Based on CAS Lock-Free Algorithm Queue for Go

Feature

Generic Support

Lightweight And Fast

Benchmark

BenchmarkGoMutexInsert-8    	 2606114	       576.9 ns/op	     103 B/op	       1 allocs/op
BenchmarkGoMutexRead-8      	 3668961	       319.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkLockFreeInsert-8   	 3465559	       379.5 ns/op	      48 B/op	       2 allocs/op
BenchmarkLockFreeRead-8     	 3687990	       336.2 ns/op	      24 B/op	       1 allocs/op
BenchmarkChannelInsert-8    	 3518539	       331.0 ns/op	      24 B/op	       1 allocs/op
BenchmarkChannelRead-8      	 3545941	       341.1 ns/op	      24 B/op	       1 allocs/op

Conclusion

However, according to the benchmark result, Golang's buffered channel is faster than CAS Lock-free Queue.

I recommend you to use golang's buffered channel as the queue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

func New

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

func (*Queue[T]) Len

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

func (*Queue[T]) Pop

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

Dequeue

func (*Queue[T]) Push

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

Enqueue

Jump to

Keyboard shortcuts

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