Documentation
¶
Overview ¶
Package gring provides a concurrent-safe/unsafe ring(circular lists).
Deprecated.
Index ¶
- type Ring
- func (r *Ring) Cap() int
- func (r *Ring) Len() int
- func (r *Ring) Link(s *Ring) *Ring
- func (r *Ring) Move(n int) *Ring
- func (r *Ring) Next() *Ring
- func (r *Ring) Prev() *Ring
- func (r *Ring) Put(value interface{}) *Ring
- func (r *Ring) RLockIteratorNext(f func(value interface{}) bool)
- func (r *Ring) RLockIteratorPrev(f func(value interface{}) bool)
- func (r *Ring) Set(value interface{}) *Ring
- func (r *Ring) SliceNext() []interface{}
- func (r *Ring) SlicePrev() []interface{}
- func (r *Ring) Unlink(n int) *Ring
- func (r *Ring) Val() interface{}
Examples ¶
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
}
Ring is a struct of ring structure.
Deprecated.
func New ¶
New creates and returns a Ring structure of `cap` elements. The optional parameter `safe` specifies whether using this structure in concurrent safety, which is false in default.
Deprecated.
func (*Ring) Link ¶
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 sub-ring and the result is a reference to that sub-ring (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) Move ¶
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) RLockIteratorNext ¶
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.
Example ¶
Output: IteratorNext Success, Value: 0 IteratorNext Success, Value: 1 IteratorNext Success, Value: 2 IteratorNext Success, Value: 3 IteratorNext Success, Value: 4
func (*Ring) RLockIteratorPrev ¶
RLockIteratorPrev 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.
Example ¶
Output: IteratorPrev Success, Value: 9 IteratorPrev Success, Value: 8 IteratorPrev Success, Value: 7 IteratorPrev Success, Value: 6 IteratorPrev Success, Value: 5
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 (*Ring) Unlink ¶
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 sub-ring. r must not be empty.
Example ¶
Output: Before Unlink, Len: 10 Before Unlink, Cap: 10 Before Unlink, [0 9 8 7 6 5 4 3 2 1] Before Unlink, [0 1 2 3 4 5 6 7 8 9] After Unlink, Len: 3 After Unlink, Cap: 3 After Unlink, [0 9 8] After Unlink, [0 8 9]