Documentation ¶
Index ¶
Constants ¶
const MaxLength = int(^uint(0) >> 1)
MaxLength is the max allowed number of elements a linked list is allowed to contain. If more elements are pushed to the list it will panic.
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) NextWait ¶
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.
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. Panics if length grows beyond the max.
func New ¶
func New() *CList
Return CList with MaxLength. CList will panic if it goes beyond MaxLength.