gring

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: MIT Imports: 3 Imported by: 3

Documentation

Overview

Package gring provides a concurrent-safe/unsafe ring(circular lists).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ring

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

func New

func New(cap int, safe ...bool) *Ring

func (*Ring) Cap

func (r *Ring) Cap() int

Cap returns the capacity of ring.

func (*Ring) Len

func (r *Ring) Len() int

Len returns the size of ring.

func (r *Ring) Link(s *Ring) *Ring

Link connects ring r with ring s such that r.Next() becomes s and returns the original value for r.Next(). r must not be empty.

If r and s point to the same ring, linking them removes the elements between r and s from the ring. The removed elements form a subring and the result is a reference to that subring (if no elements were removed, the result is still the original value for r.Next(), and not nil).

If r and s point to different rings, linking them creates a single ring with the elements of s inserted after r. The result points to the element following the last element of s after insertion.

func (*Ring) LockIteratorNext

func (r *Ring) LockIteratorNext(f func(item *ring.Ring) bool)

LockIteratorNext iterates and locks writing forward with given callback function <f> within RWMutex.RLock. If <f> returns true, then it continues iterating; or false to stop.

func (*Ring) LockIteratorPrev

func (r *Ring) LockIteratorPrev(f func(item *ring.Ring) bool)

LockIteratorPrev iterates and locks writing backward with given callback function <f> within RWMutex.RLock. If <f> returns true, then it continues iterating; or false to stop.

func (*Ring) Move

func (r *Ring) Move(n int) *Ring

Move moves n % r.Len() elements backward (n < 0) or forward (n >= 0) in the ring and returns that ring element. r must not be empty.

func (*Ring) Next

func (r *Ring) Next() *Ring

Next returns the next ring element. r must not be empty.

func (*Ring) Prev

func (r *Ring) Prev() *Ring

Prev returns the previous ring element. r must not be empty.

func (*Ring) Put

func (r *Ring) Put(value interface{}) *Ring

Put sets <value> to current item of ring and moves position to next item.

func (*Ring) RLockIteratorNext

func (r *Ring) RLockIteratorNext(f func(value interface{}) bool)

RLockIteratorNext iterates and locks reading forward with given callback function <f> within RWMutex.RLock. If <f> returns true, then it continues iterating; or false to stop.

func (*Ring) RLockIteratorPrev

func (r *Ring) RLockIteratorPrev(f func(value interface{}) bool)

RLockIteratorPrev iterates and locks reading backward with given callback function <f> within RWMutex.RLock. If <f> returns true, then it continues iterating; or false to stop.

func (*Ring) Set

func (r *Ring) Set(value interface{}) *Ring

Set sets value to the item of current position.

func (*Ring) SliceNext

func (r *Ring) SliceNext() []interface{}

SliceNext returns a copy of all item values as slice forward from current position.

func (*Ring) SlicePrev

func (r *Ring) SlicePrev() []interface{}

SlicePrev returns a copy of all item values as slice backward from current position.

func (r *Ring) Unlink(n int) *Ring

Unlink removes n % r.Len() elements from the ring r, starting at r.Next(). If n % r.Len() == 0, r remains unchanged. The result is the removed subring. r must not be empty.

func (*Ring) Val

func (r *Ring) Val() interface{}

Val returns the item's value of current position.

Jump to

Keyboard shortcuts

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