clist

package
v0.22.4-rc0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CElement

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

CElement is an element of a linked-list Traversal from a CElement is goroutine-safe.

We can't avoid using WaitGroups or for-loops given the documentation spec without re-implementing the primitives that already exist in golang/sync. Notice that WaitGroup allows many go-routines to be simultaneously released, which is what we want. Mutex doesn't do this. RWMutex does this, but it's clumsy to use in the way that a WaitGroup would be used -- and we'd end up having two RWMutex's for prev/next each, which is doubly confusing.

sync.Cond would be sort-of useful, but we don't need a write-lock in the for-loop. Use sync.Cond when you need serial access to the "condition". In our case our condition is if `next != nil || removed`, and there's no reason to serialize that condition for goroutines waiting on NextWait() (since it's just a read operation).

func (*CElement) DetachNext

func (e *CElement) DetachNext()

func (*CElement) DetachPrev

func (e *CElement) DetachPrev()

func (*CElement) Next

func (e *CElement) Next() *CElement

Nonblocking, may return nil if at the end.

func (*CElement) NextWait

func (e *CElement) NextWait() *CElement

Blocking implementation of Next(). May return nil iff CElement was tail and got removed.

func (*CElement) NextWaitChan

func (e *CElement) NextWaitChan() <-chan struct{}

NextWaitChan can be used to wait until Next becomes not nil. Once it does, channel will be closed.

func (*CElement) Prev

func (e *CElement) Prev() *CElement

Nonblocking, may return nil if at the end.

func (*CElement) PrevWait

func (e *CElement) PrevWait() *CElement

Blocking implementation of Prev(). May return nil iff CElement was head and got removed.

func (*CElement) PrevWaitChan

func (e *CElement) PrevWaitChan() <-chan struct{}

PrevWaitChan can be used to wait until Prev becomes not nil. Once it does, channel will be closed.

func (*CElement) Removed

func (e *CElement) Removed() bool

func (*CElement) SetNext

func (e *CElement) SetNext(newNext *CElement)

NOTE: This function needs to be safe for concurrent goroutines waiting on nextWg.

func (*CElement) SetPrev

func (e *CElement) SetPrev(newPrev *CElement)

NOTE: This function needs to be safe for concurrent goroutines waiting on prevWg

func (*CElement) SetRemoved

func (e *CElement) SetRemoved()

type CList

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

CList represents a linked list. The zero value for CList is an empty list ready to use. Operations are goroutine-safe.

func New

func New() *CList

func (*CList) Back

func (l *CList) Back() *CElement

func (*CList) BackWait

func (l *CList) BackWait() *CElement

func (*CList) Front

func (l *CList) Front() *CElement

func (*CList) FrontWait

func (l *CList) FrontWait() *CElement

func (*CList) Init

func (l *CList) Init() *CList

func (*CList) Len

func (l *CList) Len() int

func (*CList) PushBack

func (l *CList) PushBack(v interface{}) *CElement

func (*CList) Remove

func (l *CList) Remove(e *CElement) interface{}

CONTRACT: Caller must call e.DetachPrev() and/or e.DetachNext() to avoid memory leaks. NOTE: As per the contract of CList, removed elements cannot be added back.

func (*CList) WaitChan

func (l *CList) WaitChan() <-chan struct{}

WaitChan can be used to wait until Front or Back becomes not nil. Once it does, channel will be closed.

Jump to

Keyboard shortcuts

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