Documentation
¶
Index ¶
- type ChannelQueue
- func (cq *ChannelQueue) AsSlice() []interface{}
- func (cq *ChannelQueue) Clear()
- func (cq *ChannelQueue) Dequeue() interface{}
- func (cq *ChannelQueue) Each(consumer func(value interface{}))
- func (cq *ChannelQueue) EachUntil(consumer func(value interface{}) bool)
- func (cq *ChannelQueue) Enqueue(item interface{})
- func (cq *ChannelQueue) Len() int
- func (cq *ChannelQueue) Peek() interface{}
- func (cq *ChannelQueue) PeekBack() interface{}
- func (cq *ChannelQueue) ReverseEachUntil(consumer func(value interface{}) bool)
- type LinkedList
- func (q *LinkedList) AsSlice() []interface{}
- func (q *LinkedList) Clear()
- func (q *LinkedList) Dequeue() interface{}
- func (q *LinkedList) Each(consumer func(value interface{}))
- func (q *LinkedList) EachUntil(consumer func(value interface{}) bool)
- func (q *LinkedList) Enqueue(value interface{})
- func (q *LinkedList) Len() int
- func (q *LinkedList) Peek() interface{}
- func (q *LinkedList) PeekBack() interface{}
- func (q *LinkedList) ReverseEachUntil(consumer func(value interface{}) bool)
- type Queue
- type RateLimiter
- type RingBuffer
- func (rb *RingBuffer) AsSlice() []interface{}
- func (rb *RingBuffer) Clear()
- func (rb *RingBuffer) Dequeue() interface{}
- func (rb *RingBuffer) Drain(consumer func(value interface{}))
- func (rb *RingBuffer) Each(consumer func(value interface{}))
- func (rb *RingBuffer) EachUntil(consumer func(value interface{}) bool)
- func (rb *RingBuffer) Enqueue(object interface{})
- func (rb *RingBuffer) Len() (len int)
- func (rb *RingBuffer) Peek() interface{}
- func (rb *RingBuffer) PeekBack() interface{}
- func (rb *RingBuffer) ReverseEachUntil(consumer func(value interface{}) bool)
- func (rb *RingBuffer) String() string
- func (rb *RingBuffer) TotalLen() int
- func (rb *RingBuffer) TrimExcess()
- type SetOfInt
- func (si SetOfInt) Add(i int)
- func (si SetOfInt) AsSlice() []int
- func (si SetOfInt) Contains(i int) bool
- func (si SetOfInt) Copy() SetOfInt
- func (si SetOfInt) Difference(other SetOfInt) SetOfInt
- func (si SetOfInt) Intersect(other SetOfInt) SetOfInt
- func (si SetOfInt) IsSubsetOf(other SetOfInt) bool
- func (si SetOfInt) Len() int
- func (si SetOfInt) Remove(i int)
- func (si SetOfInt) String() string
- func (si SetOfInt) Union(other SetOfInt) SetOfInt
- type SetOfString
- func (ss SetOfString) Add(entry string)
- func (ss SetOfString) AsSlice() []string
- func (ss SetOfString) Contains(entry string) bool
- func (ss SetOfString) Copy() SetOfString
- func (ss SetOfString) Difference(other SetOfString) SetOfString
- func (ss SetOfString) Intersect(other SetOfString) SetOfString
- func (ss SetOfString) IsSubsetOf(other SetOfString) bool
- func (ss SetOfString) Len() int
- func (ss SetOfString) Remove(entry string) bool
- func (ss SetOfString) String() string
- func (ss SetOfString) Union(other SetOfString) SetOfString
- type StringArray
- type SynchronizedRingBuffer
- func (srb *SynchronizedRingBuffer) AsSlice() (val []interface{})
- func (srb *SynchronizedRingBuffer) Clear()
- func (srb *SynchronizedRingBuffer) Dequeue() (val interface{})
- func (srb *SynchronizedRingBuffer) Drain(consumer func(value interface{}))
- func (srb *SynchronizedRingBuffer) Each(consumer func(value interface{}))
- func (srb *SynchronizedRingBuffer) EachUntil(consumer func(value interface{}) bool)
- func (srb *SynchronizedRingBuffer) Enqueue(value interface{})
- func (srb *SynchronizedRingBuffer) InnerBuffer() *RingBuffer
- func (srb SynchronizedRingBuffer) Len() (val int)
- func (srb *SynchronizedRingBuffer) Peek() (val interface{})
- func (srb *SynchronizedRingBuffer) PeekBack() (val interface{})
- func (srb *SynchronizedRingBuffer) ReverseEachUntil(consumer func(value interface{}) bool)
- func (srb *SynchronizedRingBuffer) SyncRoot() *sync.Mutex
- func (srb *SynchronizedRingBuffer) TotalLen() (val int)
- func (srb *SynchronizedRingBuffer) TrimExcess()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelQueue ¶
type ChannelQueue struct { MaxSize int // contains filtered or unexported fields }
ChannelQueue is a threadsafe queue.
func (*ChannelQueue) AsSlice ¶
func (cq *ChannelQueue) AsSlice() []interface{}
AsSlice iterates over the queue and returns an array of its contents.
func (*ChannelQueue) Dequeue ¶
func (cq *ChannelQueue) Dequeue() interface{}
Dequeue returns the next element in the queue.
func (*ChannelQueue) Each ¶
func (cq *ChannelQueue) Each(consumer func(value interface{}))
Each pulls every value out of the channel, calls consumer on it, and puts it back.
func (*ChannelQueue) EachUntil ¶
func (cq *ChannelQueue) EachUntil(consumer func(value interface{}) bool)
EachUntil pulls every value out of the channel, calls consumer on it, and puts it back and can abort mid process.
func (*ChannelQueue) Enqueue ¶
func (cq *ChannelQueue) Enqueue(item interface{})
Enqueue adds an item to the queue.
func (*ChannelQueue) Len ¶
func (cq *ChannelQueue) Len() int
Len returns the number of items in the queue.
func (*ChannelQueue) Peek ¶
func (cq *ChannelQueue) Peek() interface{}
Peek returns (but does not remove) the first element of the queue.
func (*ChannelQueue) PeekBack ¶
func (cq *ChannelQueue) PeekBack() interface{}
PeekBack returns (but does not remove) the last element of the queue.
func (*ChannelQueue) ReverseEachUntil ¶
func (cq *ChannelQueue) ReverseEachUntil(consumer func(value interface{}) bool)
ReverseEachUntil pulls every value out of the channel, calls consumer on it, and puts it back and can abort mid process.
type LinkedList ¶
type LinkedList struct {
// contains filtered or unexported fields
}
LinkedList is an implementation of a fifo buffer using nodes and poitners. Remarks; it is not threadsafe. It is constant(ish) time in all ops.
func (*LinkedList) AsSlice ¶
func (q *LinkedList) AsSlice() []interface{}
AsSlice returns the full contents of the queue as a slice.
func (*LinkedList) Dequeue ¶
func (q *LinkedList) Dequeue() interface{}
Dequeue removes an item from the front of the queue and returns it.
func (*LinkedList) Each ¶
func (q *LinkedList) Each(consumer func(value interface{}))
Each calls the consumer for each element of the linked list.
func (*LinkedList) EachUntil ¶
func (q *LinkedList) EachUntil(consumer func(value interface{}) bool)
EachUntil calls the consumer for each element of the linked list, but can abort.
func (*LinkedList) Enqueue ¶
func (q *LinkedList) Enqueue(value interface{})
Enqueue adds a new value to the queue.
func (*LinkedList) Len ¶
func (q *LinkedList) Len() int
Len returns the length of the queue in constant time.
func (*LinkedList) Peek ¶
func (q *LinkedList) Peek() interface{}
Peek returns the first element of the queue but does not remove it.
func (*LinkedList) PeekBack ¶
func (q *LinkedList) PeekBack() interface{}
PeekBack returns the last element of the queue.
func (*LinkedList) ReverseEachUntil ¶
func (q *LinkedList) ReverseEachUntil(consumer func(value interface{}) bool)
ReverseEachUntil calls the consumer for each element of the linked list, but can abort.
type Queue ¶
type Queue interface { Len() int Enqueue(value interface{}) Dequeue() interface{} Peek() interface{} PeekBack() interface{} AsSlice() []interface{} Clear() Each(consumer func(value interface{})) EachUntil(consumer func(value interface{}) bool) ReverseEachUntil(consumer func(value interface{}) bool) }
Queue is an interface for implementations of a FIFO buffer.
func NewChannelQueue ¶
NewChannelQueue returns a new ConcurrentQueue instance.
type RateLimiter ¶
RateLimiter is a simple implementation of a rate checker.
func NewRateLimiter ¶
func NewRateLimiter(numberOfActions int, quantum time.Duration) *RateLimiter
NewRateLimiter returns a new RateLimiter instance.
func (*RateLimiter) Check ¶
func (rl *RateLimiter) Check(id string) bool
Check returns true if it has been called NumberOfActions times or more in Quantum or smaller duration.
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a fifo buffer that is backed by a pre-allocated array, instead of allocating a whole new node object for each element (which saves GC churn). Enqueue can be O(n), Dequeue can be O(1).
func NewRingBuffer ¶
func NewRingBuffer() *RingBuffer
NewRingBuffer creates a new, empty, RingBuffer.
func NewRingBufferFromSlice ¶
func NewRingBufferFromSlice(values []interface{}) *RingBuffer
NewRingBufferFromSlice createsa ring buffer out of a slice.
func NewRingBufferWithCapacity ¶
func NewRingBufferWithCapacity(capacity int) *RingBuffer
NewRingBufferWithCapacity creates a new RingBuffer pre-allocated with the given capacity.
func (*RingBuffer) AsSlice ¶
func (rb *RingBuffer) AsSlice() []interface{}
AsSlice returns the ring buffer, in order, as a slice.
func (*RingBuffer) Clear ¶
func (rb *RingBuffer) Clear()
Clear removes all objects from the RingBuffer.
func (*RingBuffer) Dequeue ¶
func (rb *RingBuffer) Dequeue() interface{}
Dequeue removes the first (oldest) element from the RingBuffer.
func (*RingBuffer) Drain ¶
func (rb *RingBuffer) Drain(consumer func(value interface{}))
Drain calls the consumer for each element in the buffer, while also dequeueing that entry.
func (*RingBuffer) Each ¶
func (rb *RingBuffer) Each(consumer func(value interface{}))
Each calls the consumer for each element in the buffer.
func (*RingBuffer) EachUntil ¶
func (rb *RingBuffer) EachUntil(consumer func(value interface{}) bool)
EachUntil calls the consumer for each element in the buffer with a stopping condition in head=>tail order.
func (*RingBuffer) Enqueue ¶
func (rb *RingBuffer) Enqueue(object interface{})
Enqueue adds an element to the "back" of the RingBuffer.
func (*RingBuffer) Len ¶
func (rb *RingBuffer) Len() (len int)
Len returns the length of the ring buffer (as it is currently populated). Actual memory footprint may be different.
func (*RingBuffer) Peek ¶
func (rb *RingBuffer) Peek() interface{}
Peek returns but does not remove the first element.
func (*RingBuffer) PeekBack ¶
func (rb *RingBuffer) PeekBack() interface{}
PeekBack returns but does not remove the last element.
func (*RingBuffer) ReverseEachUntil ¶
func (rb *RingBuffer) ReverseEachUntil(consumer func(value interface{}) bool)
ReverseEachUntil calls the consumer for each element in the buffer with a stopping condition in tail=>head order.
func (*RingBuffer) String ¶
func (rb *RingBuffer) String() string
func (*RingBuffer) TotalLen ¶
func (rb *RingBuffer) TotalLen() int
TotalLen returns the total size of the ring bufffer, including empty elements.
func (*RingBuffer) TrimExcess ¶
func (rb *RingBuffer) TrimExcess()
TrimExcess resizes the buffer to better fit the contents.
type SetOfInt ¶
SetOfInt is a type alias for map[int]int
func (SetOfInt) Difference ¶
Difference returns non-shared elements between two sets.
func (SetOfInt) IsSubsetOf ¶
IsSubsetOf returns if a given set is a complete subset of another set, i.e. all elements in target set are in other set.
type SetOfString ¶
SetOfString is a set of strings
func NewSetOfString ¶
func NewSetOfString(values ...string) SetOfString
NewSetOfString creates a new SetOfString.
func (SetOfString) AsSlice ¶
func (ss SetOfString) AsSlice() []string
AsSlice returns the set as a slice.
func (SetOfString) Contains ¶
func (ss SetOfString) Contains(entry string) bool
Contains returns if an element is in the set.
func (SetOfString) Copy ¶
func (ss SetOfString) Copy() SetOfString
Copy returns a new copy of the set.
func (SetOfString) Difference ¶
func (ss SetOfString) Difference(other SetOfString) SetOfString
Difference returns non-shared elements between two sets.
func (SetOfString) Intersect ¶
func (ss SetOfString) Intersect(other SetOfString) SetOfString
Intersect returns shared elements between two sets.
func (SetOfString) IsSubsetOf ¶
func (ss SetOfString) IsSubsetOf(other SetOfString) bool
IsSubsetOf returns if a given set is a complete subset of another set, i.e. all elements in target set are in other set.
func (SetOfString) Remove ¶
func (ss SetOfString) Remove(entry string) bool
Remove deletes an element, returns if the element was in the set.
func (SetOfString) String ¶
func (ss SetOfString) String() string
String returns the set as a csv string.
func (SetOfString) Union ¶
func (ss SetOfString) Union(other SetOfString) SetOfString
Union joins two sets together without dupes.
type StringArray ¶
type StringArray []string
StringArray is a type alias for []string with some helper methods.
func (StringArray) Contains ¶
func (sa StringArray) Contains(elem string) bool
Contains returns if the given string is in the array.
func (StringArray) ContainsLower ¶
func (sa StringArray) ContainsLower(elem string) bool
ContainsLower returns true if the `elem` is in the StringArray, false otherwise.
func (StringArray) GetByLower ¶
func (sa StringArray) GetByLower(elem string) string
GetByLower returns an element from the array that matches the input.
type SynchronizedRingBuffer ¶
type SynchronizedRingBuffer struct {
// contains filtered or unexported fields
}
SynchronizedRingBuffer is a ring buffer wrapper that adds synchronization.
func NewSynchronizedRingBuffer ¶
func NewSynchronizedRingBuffer() *SynchronizedRingBuffer
NewSynchronizedRingBuffer returns a new synchronized ring buffer.
func NewSynchronizedRingBufferWithCapacity ¶
func NewSynchronizedRingBufferWithCapacity(capacity int) *SynchronizedRingBuffer
NewSynchronizedRingBufferWithCapacity retrns a new synchronized ring buffer with a given initial capacity.
func (*SynchronizedRingBuffer) AsSlice ¶
func (srb *SynchronizedRingBuffer) AsSlice() (val []interface{})
AsSlice returns the ring buffer, in order, as a slice.
func (*SynchronizedRingBuffer) Clear ¶
func (srb *SynchronizedRingBuffer) Clear()
Clear removes all objects from the RingBuffer.
func (*SynchronizedRingBuffer) Dequeue ¶
func (srb *SynchronizedRingBuffer) Dequeue() (val interface{})
Dequeue removes the first (oldest) element from the RingBuffer.
func (*SynchronizedRingBuffer) Drain ¶
func (srb *SynchronizedRingBuffer) Drain(consumer func(value interface{}))
Drain calls the consumer for each element in the buffer, while also dequeueing that entry.
func (*SynchronizedRingBuffer) Each ¶
func (srb *SynchronizedRingBuffer) Each(consumer func(value interface{}))
Each calls the consumer for each element in the buffer.
func (*SynchronizedRingBuffer) EachUntil ¶
func (srb *SynchronizedRingBuffer) EachUntil(consumer func(value interface{}) bool)
EachUntil calls the consumer for each element in the buffer with a stopping condition in head=>tail order.
func (*SynchronizedRingBuffer) Enqueue ¶
func (srb *SynchronizedRingBuffer) Enqueue(value interface{})
Enqueue adds an element to the "back" of the RingBuffer.
func (*SynchronizedRingBuffer) InnerBuffer ¶
func (srb *SynchronizedRingBuffer) InnerBuffer() *RingBuffer
InnerBuffer returns the inner ringbuffer.
func (SynchronizedRingBuffer) Len ¶
func (srb SynchronizedRingBuffer) Len() (val int)
Len returns the length of the ring buffer (as it is currently populated). Actual memory footprint may be different.
func (*SynchronizedRingBuffer) Peek ¶
func (srb *SynchronizedRingBuffer) Peek() (val interface{})
Peek returns but does not remove the first element.
func (*SynchronizedRingBuffer) PeekBack ¶
func (srb *SynchronizedRingBuffer) PeekBack() (val interface{})
PeekBack returns but does not remove the last element.
func (*SynchronizedRingBuffer) ReverseEachUntil ¶
func (srb *SynchronizedRingBuffer) ReverseEachUntil(consumer func(value interface{}) bool)
ReverseEachUntil calls the consumer for each element in the buffer with a stopping condition in tail=>head order.
func (*SynchronizedRingBuffer) SyncRoot ¶
func (srb *SynchronizedRingBuffer) SyncRoot() *sync.Mutex
SyncRoot returns the mutex used to synchronize the collection.
func (*SynchronizedRingBuffer) TotalLen ¶
func (srb *SynchronizedRingBuffer) TotalLen() (val int)
TotalLen returns the total size of the ring bufffer, including empty elements.
func (*SynchronizedRingBuffer) TrimExcess ¶
func (srb *SynchronizedRingBuffer) TrimExcess()
TrimExcess resizes the buffer to better fit the contents.