Documentation
¶
Overview ¶
Package goqueue provides common types and functions used by all implementations of a queue
Index ¶
- func AssertExamples(example *Example, examples []*Example) func() bool
- func MustDequeue(queue Dequeuer, done <-chan struct{}, rate time.Duration) (interface{}, bool)
- func MustDequeueEvent(queue interface{ ... }, done <-chan struct{}) (interface{}, bool)
- func MustDequeueMultiple(queue Dequeuer, done <-chan struct{}, n int, rate time.Duration) []interface{}
- func MustDequeueMultipleEvent(queue interface{ ... }, done <-chan struct{}, n int) []interface{}
- func MustEnqueue(queue Enqueuer, item interface{}, done <-chan struct{}, rate time.Duration) bool
- func MustEnqueueEvent(queue interface{ ... }, item interface{}, done <-chan struct{}) bool
- func MustEnqueueMultiple(queue Enqueuer, items []interface{}, done <-chan struct{}, rate time.Duration) ([]interface{}, bool)
- func MustEnqueueMultipleEvent(queue interface{ ... }, items []interface{}, done <-chan struct{}) ([]interface{}, bool)
- func MustFlush(queue Dequeuer, done <-chan struct{}, rate time.Duration) []interface{}
- func MustFlushEvent(queue interface{ ... }, done <-chan struct{}) []interface{}
- func MustPeek(queue Peeker, done <-chan struct{}, rate time.Duration) []interface{}
- func MustPeekEvent(queue interface{ ... }, done <-chan struct{}) []interface{}
- func MustPeekFromHead(queue Peeker, done <-chan struct{}, n int, rate time.Duration) []interface{}
- func MustPeekFromHeadEvent(queue interface{ ... }, done <-chan struct{}, n int) []interface{}
- func MustPeekHead(queue Peeker, done <-chan struct{}, rate time.Duration) (interface{}, bool)
- func MustPeekHeadEvent(queue interface{ ... }, done <-chan struct{}) (interface{}, bool)
- type BinaryMarshaler
- type BinaryUnmarshaler
- type Bytes
- type Dequeuer
- type EnqueueInFronter
- type Enqueuer
- type Event
- type Example
- func ExampleClose(queue Owner) []*Example
- func ExampleConvertMultiple(items []interface{}) []*Example
- func ExampleConvertSingle(item interface{}) *Example
- func ExampleDequeue(queue Dequeuer) (*Example, bool)
- func ExampleDequeueMultiple(queue Dequeuer, n int) []*Example
- func ExampleEnqueueMultiple(queue Enqueuer, values []*Example) ([]*Example, bool)
- func ExampleFlush(queue Dequeuer) []*Example
- func ExampleGen(sizes ...int) []*Example
- func ExampleGenFloat64(sizes ...int) []*Example
- func ExampleGenInt(sizes ...int) []*Example
- func ExampleGenString(sizes ...int) []*Example
- func ExamplePeek(queue Peeker) []*Example
- func ExamplePeekFromHead(queue Peeker, n int) []*Example
- func ExamplePeekHead(queue Peeker) (*Example, bool)
- type GarbageCollecter
- type Length
- type Owner
- type Peeker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertExamples ¶ added in v1.2.2
func MustDequeue ¶ added in v1.2.2
MustDequeue will attempt to dequeue at least one item at the rate configured until the done channel signals. KIM: It's possible to provide a nil channel and this function will block (forever) until a dequeue is successful
func MustDequeueEvent ¶ added in v1.2.2
func MustDequeueMultiple ¶ added in v1.2.2
func MustDequeueMultipleEvent ¶ added in v1.2.2
func MustEnqueue ¶ added in v1.2.2
MustEnqueue will attempt to use the Enqueue() function until the enqueue is successful (no overflow); this function will block until success occurs or the done channel receives a signal. An enqueue will attempt to occur at the rate configured
func MustEnqueueEvent ¶ added in v1.2.2
func MustEnqueueEvent(queue interface { Enqueuer Event }, item interface{}, done <-chan struct{}) bool
MustEnqueue will attempt to use the Enqueue() function until the enqueue is successful (no overflow); this function will block until success occurs or the done channel receives a signal. An enqueue will be attempted for every signal received
func MustEnqueueMultiple ¶ added in v1.2.2
func MustEnqueueMultiple(queue Enqueuer, items []interface{}, done <-chan struct{}, rate time.Duration) ([]interface{}, bool)
MustEnqueueMultiple will attempt to enqueue until the done channel completes,
at the configured rate or the number of elements are successfully enqueued into the provided queue
KIM: this function doesn't preserve the unit of work and may not be consistent with concurent usage (although it is safe)
func MustEnqueueMultipleEvent ¶ added in v1.2.2
func MustEnqueueMultipleEvent(queue interface { Enqueuer Event }, items []interface{}, done <-chan struct{}) ([]interface{}, bool)
MustEnqueueMultipleEvent will attempt to enqueue one or more items, upon initial failure, it'll use the event channels/signals to attempt to enqueue items KIM: this function doesn't preserve the unit of work and may not be consistent with concurent usage (although it is safe)
func MustFlushEvent ¶ added in v1.2.2
func MustPeekEvent ¶ added in v1.2.2
func MustPeekFromHead ¶ added in v1.2.2
func MustPeekFromHeadEvent ¶ added in v1.2.2
func MustPeekHead ¶ added in v1.2.2
func MustPeekHeadEvent ¶ added in v1.2.2
Types ¶
type BinaryMarshaler ¶ added in v1.2.0
type BinaryMarshaler = encoding.BinaryMarshaler
These types are specifically provided to attempt to communicate support for how queues would be able to store data in a persistent way no matter the data type (empty interface)
type BinaryUnmarshaler ¶ added in v1.2.0
type BinaryUnmarshaler = encoding.BinaryUnmarshaler
These types are specifically provided to attempt to communicate support for how queues would be able to store data in a persistent way no matter the data type (empty interface)
type Bytes ¶ added in v1.2.0
type Bytes []byte
Bytes is provided to make it easier to create jagged arrays; two dimensional arrays are nice, but they work off the idea that each row has the same number of elements which doesnt work for the use case for a queue... KIM: Bytes is a type that can be used to traverse package boundaries unlike an anonymous struct or Bytes defined by some other package
type Dequeuer ¶
type Dequeuer interface { Dequeue() (item interface{}, underflow bool) DequeueMultiple(n int) (items []interface{}) Flush() (items []interface{}) }
Dequeuer can be used to destructively remove one or more items from the queue, it can remove one item via Dequeue(), multiple items via DequeueMultiple() or all items using Flush() underflow will be true if the queue is empty
type EnqueueInFronter ¶
type EnqueueInFronter interface {
EnqueueInFront(item interface{}) (overflow bool)
}
EnqueueInFronter describes an operation where you enqueue a single item at the front of the queue, if the queue is full overflow will be true
type Enqueuer ¶
type Enqueuer interface { Enqueue(item interface{}) (overflow bool) EnqueueMultiple(items []interface{}) (itemsRemaining []interface{}, overflow bool) }
Enqueuer can be used to put one or more items into the queue Enqueue() can be used to place one item while EnqueueMultiple() can be used to place multiple items, in the event the queue is full the remaining items will be provided (if applicable) and overflow will be true
type Event ¶
type Event interface { GetSignalIn() (signal <-chan struct{}) GetSignalOut() (signal <-chan struct{}) }
Event can be used to get a read-only signal that would indicate whether data was removed from the queue (out) or put into the queue (in). Keep in mind that whether the channel is buffered or un-buffered depends on the underlying implementation
type Example ¶ added in v1.2.0
type Example struct { Int int `json:"int,omitempty"` Float float64 `json:"float,omitempty,string"` String string `json:"string,omitempty"` }
func ExampleClose ¶ added in v1.2.0
func ExampleConvertMultiple ¶ added in v1.2.0
func ExampleConvertMultiple(items []interface{}) []*Example
func ExampleConvertSingle ¶ added in v1.2.0
func ExampleConvertSingle(item interface{}) *Example
func ExampleDequeue ¶ added in v1.2.0
func ExampleDequeueMultiple ¶ added in v1.2.0
func ExampleEnqueueMultiple ¶ added in v1.2.0
func ExampleFlush ¶ added in v1.2.0
func ExampleGen ¶ added in v1.2.2
func ExampleGenFloat64 ¶ added in v1.2.0
ExampleGenFloat64 will generate a random number of random float values if n is equal to 0 not to exceed the constant TestMaxExamples, if n is provided, it will generate that many items
func ExampleGenInt ¶ added in v1.2.2
func ExampleGenString ¶ added in v1.2.2
func ExamplePeek ¶ added in v1.2.0
func ExamplePeekFromHead ¶ added in v1.2.0
func ExamplePeekHead ¶ added in v1.2.0
func (*Example) MarshalBinary ¶ added in v1.2.0
func (*Example) UnmarshalBinary ¶ added in v1.2.0
type GarbageCollecter ¶
type GarbageCollecter interface {
GarbageCollect()
}
GarbageCollecter can be implemented to re-create the underlying pointers so that they can be garabge collected, you can think of this as creating an opportunity to defrag the memory
type Length ¶ added in v1.2.0
type Length interface {
Length() (size int)
}
Length can be used to determine how many items are inside a queue at any given time
type Owner ¶
type Owner interface {
Close() (items []interface{})
}
Owner provides functions that directly affect the underlying pointers and data structures of a queue pointers. The Close() function should ready the underlying pointer for garbage collection and return a slice of any items that remain in the queue
type Peeker ¶
type Peeker interface { Peek() (items []interface{}) PeekHead() (item interface{}, underflow bool) PeekFromHead(n int) (items []interface{}) }
Peeker can be used to non-destructively remove one or more items from the queue, it can remove all items via Peek(), remove an item from the front of the queue via PeekHead() or remove multiple items via PeekFromHead(). Underflow will be true, if the queue is empty
Directories
¶
Path | Synopsis |
---|---|
Package finite provides common types and functions used by a finite queue implementation
|
Package finite provides common types and functions used by a finite queue implementation |
tests
Package finite_tests provides a test suite for finite queues
|
Package finite_tests provides a test suite for finite queues |
Package infinite provides common types and functions used by a infinite queue implementation
|
Package infinite provides common types and functions used by a infinite queue implementation |
tests
Package infinite_tests provides a test suite for infinite queues
|
Package infinite_tests provides a test suite for infinite queues |
Package goqueue_tests provides a test suite for general queues
|
Package goqueue_tests provides a test suite for general queues |