Documentation
¶
Index ¶
- Constants
- func All[T any](slice []T, predicate func(T) bool) bool
- func Any[T any](slice []T, predicate func(T) bool) bool
- func B2F(b bool) float64
- func B2I(b bool) int
- func CopySlice[T any](src []T) []T
- func ExtractStringValue(pattern, input string) (string, error)
- func IsLineIntersect(line1Points, line2Points []float64) bool
- func IsLineIntersectCyclic(line1Points, line2Points *CyclicSlice[float64]) bool
- func MapKeys[K comparable, V any](m map[K]V) []K
- func MapValues[K comparable, V any](m map[K]V) []V
- func Max[T Ordered](a, b T) T
- func Min[T Ordered](a, b T) T
- func ParseList[T any](input, pattern, delimiter string) ([]T, error)
- func ParseValue[T any](input, pattern string) (T, error)
- type BackwardIterator
- type Batcher
- type Color
- type Comparator
- type CyclicSlice
- func (cs *CyclicSlice[T]) Add(value T)
- func (cs *CyclicSlice[T]) GetAt(index int) T
- func (cs *CyclicSlice[T]) GetCurrentSize() int
- func (cs *CyclicSlice[T]) GetData() []T
- func (cs *CyclicSlice[T]) GetLast() T
- func (cs *CyclicSlice[T]) GetPrevious() T
- func (cs *CyclicSlice[T]) IsFull() bool
- func (cs *CyclicSlice[T]) Reset()
- func (cs *CyclicSlice[T]) SetAt(index int, value T)
- type DayCacheManager
- type DaySingleBigCacheManager
- type DoublyLinkedList
- func (ll *DoublyLinkedList[T]) Add(value T) *DoublyLinkedNode[T]
- func (ll *DoublyLinkedList[T]) AddSorted(value T, less func(a, b T) bool) *DoublyLinkedNode[T]
- func (ll *DoublyLinkedList[T]) Cleanup(valueCleanup func(T))
- func (ll *DoublyLinkedList[T]) Merge(other *DoublyLinkedList[T])
- func (ll *DoublyLinkedList[T]) MergeSort(comparator func(a, b T) bool)
- func (ll *DoublyLinkedList[T]) NewBackwardIterator() *BackwardIterator[T]
- func (ll *DoublyLinkedList[T]) NewIterator() *Iterator[T]
- func (ll *DoublyLinkedList[T]) Remove(node *DoublyLinkedNode[T])
- func (ll *DoublyLinkedList[T]) Reset()
- func (ll *DoublyLinkedList[T]) ResetWithCleanup()
- func (ll *DoublyLinkedList[T]) Size() int
- func (ll *DoublyLinkedList[T]) Tail() *DoublyLinkedNode[T]
- type DoublyLinkedNode
- type Item
- type Iterator
- type ObjectPool
- type Ordered
- type PriorityQueueComparator
- type PriorityQueueInterface
- type RBNode
- type RBTree
- type Semaphore
- type Task
- type TimeIntervalCache
- type TimeUtil
- func (tu TimeUtil) AddDate(years int, months int, days int) TimeUtil
- func (tu TimeUtil) After(u TimeUtil) bool
- func (tu TimeUtil) Before(u TimeUtil) bool
- func (tu TimeUtil) Equal(u TimeUtil) bool
- func (tu TimeUtil) RFC3339FormatDate() string
- func (tu TimeUtil) StockFormatDate() string
- func (tu TimeUtil) String() string
- func (tu TimeUtil) Unix() int64
- type WorkerPool
Constants ¶
const ( STOCK_DATE_FORMAT_LAYOUT = "2006-01-02" RFC3339_TIME_LAYOUT = "2006-01-02T15:04:05Z07:00" // RFC3339 format )
Variables ¶
This section is empty.
Functions ¶
func CopySlice ¶
func CopySlice[T any](src []T) []T
CopySlice creates a copy of the given slice of any type.
func ExtractStringValue ¶
Utility function to extract a string value using a regex pattern
func IsLineIntersect ¶
func IsLineIntersectCyclic ¶
func IsLineIntersectCyclic(line1Points, line2Points *CyclicSlice[float64]) bool
func MapKeys ¶
func MapKeys[K comparable, V any](m map[K]V) []K
MapKeys extracts the keys of a map into a slice.
func MapValues ¶
func MapValues[K comparable, V any](m map[K]V) []V
MapValues extracts the values of a map into a slice.
func ParseValue ¶
Utility function to extract a value using a regex pattern and convert it to type T
Types ¶
type BackwardIterator ¶
type BackwardIterator[T any] struct { // contains filtered or unexported fields }
BackwardIterator represents an iterator for traversing the list in reverse order.
func (*BackwardIterator[T]) HasPrev ¶
func (it *BackwardIterator[T]) HasPrev() bool
HasPrev checks if there is a previous node available in the list.
func (*BackwardIterator[T]) Prev ¶
func (it *BackwardIterator[T]) Prev() *DoublyLinkedNode[T]
Prev moves the iterator to the previous node and returns the current node.
func (*BackwardIterator[T]) Remove ¶
func (it *BackwardIterator[T]) Remove()
Remove removes the current node from the list during backward iteration.
type Batcher ¶
type Batcher[T any] struct { // contains filtered or unexported fields }
Batcher is a struct that batches data using a cyclic slice and returns batches in real-time.
func NewBatcher ¶
NewBatcherWithCyclicSlice creates a new Batcher with a specified batch size and cyclic buffer size.
func (*Batcher[T]) AddAndGet ¶
func (b *Batcher[T]) AddAndGet(item T) []T
Add adds a new item to the batcher and returns a batch if the batch size is met.
func (*Batcher[T]) ProcessorViaChannel ¶
func (b *Batcher[T]) ProcessorViaChannel(items gr_variable.ReadOnlyGrChannel[T], processFunc func(batch []T))
type Color ¶
type Color bool
Color is a type representing the color of a node in the Red-Black Tree.
type Comparator ¶
Comparator is a function type that compares two values of type T and returns true if the first is less than the second.
type CyclicSlice ¶
type CyclicSlice[T any] struct { // contains filtered or unexported fields }
func NewCyclicSlice ¶
func NewCyclicSlice[T any](size int) *CyclicSlice[T]
func (*CyclicSlice[T]) Add ¶
func (cs *CyclicSlice[T]) Add(value T)
func (*CyclicSlice[T]) GetAt ¶
func (cs *CyclicSlice[T]) GetAt(index int) T
func (*CyclicSlice[T]) GetCurrentSize ¶
func (cs *CyclicSlice[T]) GetCurrentSize() int
func (*CyclicSlice[T]) GetData ¶
func (cs *CyclicSlice[T]) GetData() []T
func (*CyclicSlice[T]) GetLast ¶
func (cs *CyclicSlice[T]) GetLast() T
func (*CyclicSlice[T]) GetPrevious ¶
func (cs *CyclicSlice[T]) GetPrevious() T
func (*CyclicSlice[T]) IsFull ¶
func (cs *CyclicSlice[T]) IsFull() bool
func (*CyclicSlice[T]) Reset ¶
func (cs *CyclicSlice[T]) Reset()
func (*CyclicSlice[T]) SetAt ¶
func (cs *CyclicSlice[T]) SetAt(index int, value T)
type DayCacheManager ¶
type DayCacheManager[T any] struct { // contains filtered or unexported fields }
DayCacheManager is a generic structure to manage caching for an indicator adaptor
func NewDayCacheManager ¶
func NewDayCacheManager[T any](dayInterval, hourInterval int64, defaultValue T, dayIntervalPool *ObjectPool[TimeIntervalCache[T]], dayPool *ObjectPool[TimeIntervalCache[*TimeIntervalCache[T]]]) *DayCacheManager[T]
NewDayCacheManager creates a new DayCacheManager instance
func (*DayCacheManager[T]) CleanUp ¶
func (dcm *DayCacheManager[T]) CleanUp()
CleanUp cleans up all the caches
func (*DayCacheManager[T]) Get ¶
func (dcm *DayCacheManager[T]) Get(timestamp int64) T
Get retrieves a value from the cache based on the timestamp
func (*DayCacheManager[T]) Set ¶
func (dcm *DayCacheManager[T]) Set(timestamp int64, value T)
Set adds a value to the appropriate time cache within the day
type DaySingleBigCacheManager ¶
type DaySingleBigCacheManager[T any] struct { // contains filtered or unexported fields }
DaySingleBigCacheManager is a generic structure to manage caching for an indicator adaptor
func NewDaySingleBigCacheManager ¶
func NewDaySingleBigCacheManager[T any](hourInterval int64, defaultValue T, dayIntervalPool *ObjectPool[TimeIntervalCache[T]]) *DaySingleBigCacheManager[T]
NewDaySingleBigCacheManager creates a new DaySingleBigCacheManager instance
func (*DaySingleBigCacheManager[T]) CleanUp ¶
func (dcm *DaySingleBigCacheManager[T]) CleanUp()
CleanUp cleans up all the caches
func (*DaySingleBigCacheManager[T]) Get ¶
func (dcm *DaySingleBigCacheManager[T]) Get(timestamp int64) T
Get retrieves a value from the cache based on the timestamp
func (*DaySingleBigCacheManager[T]) Set ¶
func (dcm *DaySingleBigCacheManager[T]) Set(timestamp int64, value T)
Set adds a value to the appropriate time cache within the day
type DoublyLinkedList ¶
type DoublyLinkedList[T any] struct { // contains filtered or unexported fields }
DoublyLinkedList represents the doubly linked list structure.
func NewDoublyLinkedListWithPool ¶
func NewDoublyLinkedListWithPool[T any](dllnPool *ObjectPool[DoublyLinkedNode[T]], dllPool *ObjectPool[DoublyLinkedList[T]]) *DoublyLinkedList[T]
NewDoublyLinkedListWithPool creates a new DoublyLinkedList with a specific dllnPool.
func (*DoublyLinkedList[T]) Add ¶
func (ll *DoublyLinkedList[T]) Add(value T) *DoublyLinkedNode[T]
Add appends a new element to the end of the list.
func (*DoublyLinkedList[T]) AddSorted ¶
func (ll *DoublyLinkedList[T]) AddSorted(value T, less func(a, b T) bool) *DoublyLinkedNode[T]
AddSorted inserts a value into the list while maintaining sorted order. The 'less' function defines the comparison logic.
func (*DoublyLinkedList[T]) Cleanup ¶
func (ll *DoublyLinkedList[T]) Cleanup(valueCleanup func(T))
Cleanup releases all nodes in the list back to the dllnPool.
func (*DoublyLinkedList[T]) Merge ¶
func (ll *DoublyLinkedList[T]) Merge(other *DoublyLinkedList[T])
Merge appends another doubly linked list into the current list.
func (*DoublyLinkedList[T]) MergeSort ¶
func (ll *DoublyLinkedList[T]) MergeSort(comparator func(a, b T) bool)
MergeSort sorts the doubly linked list using the Merge MergeSort algorithm and the provided comparator function.
func (*DoublyLinkedList[T]) NewBackwardIterator ¶
func (ll *DoublyLinkedList[T]) NewBackwardIterator() *BackwardIterator[T]
NewBackwardIterator creates a new backward iterator for the linked list, starting from the tail.
func (*DoublyLinkedList[T]) NewIterator ¶
func (ll *DoublyLinkedList[T]) NewIterator() *Iterator[T]
NewIterator creates a new iterator for the linked list.
func (*DoublyLinkedList[T]) Remove ¶
func (ll *DoublyLinkedList[T]) Remove(node *DoublyLinkedNode[T])
Remove removes the given node from the list in O(1) time and returns it to the dllnPool.
func (*DoublyLinkedList[T]) Reset ¶
func (ll *DoublyLinkedList[T]) Reset()
func (*DoublyLinkedList[T]) ResetWithCleanup ¶
func (ll *DoublyLinkedList[T]) ResetWithCleanup()
func (*DoublyLinkedList[T]) Size ¶
func (ll *DoublyLinkedList[T]) Size() int
Size returns the number of elements in the list.
func (*DoublyLinkedList[T]) Tail ¶
func (ll *DoublyLinkedList[T]) Tail() *DoublyLinkedNode[T]
Tail returns the number of elements in the list.
type DoublyLinkedNode ¶
type DoublyLinkedNode[T any] struct { Value T Next *DoublyLinkedNode[T] Prev *DoublyLinkedNode[T] }
DoublyLinkedNode represents a node in the doubly linked list.
type Iterator ¶
type Iterator[T any] struct { // contains filtered or unexported fields }
Iterator represents an iterator for the doubly linked list.
func (*Iterator[T]) Next ¶
func (it *Iterator[T]) Next() *DoublyLinkedNode[T]
Next moves the iterator to the next node and returns the current node.
type ObjectPool ¶
type ObjectPool[T any] struct { // contains filtered or unexported fields }
ObjectPool is a wrapper around sync.Pool that provides type-safe pooling for any type T.
func NewObjectPool ¶
func NewObjectPool[T any]() *ObjectPool[T]
NewObjectPool creates a new ObjectPool for a given type T.
func (*ObjectPool[T]) Get ¶
func (p *ObjectPool[T]) Get() *T
Get retrieves a node from the pool, or creates a new one if none are available.
type PriorityQueueComparator ¶
PriorityQueueComparator function type, returns true if a should come before b.
type PriorityQueueInterface ¶
type PriorityQueueInterface[T any] interface { Insert(value T) Remove() T }
PriorityQueueInterface defines the public methods for the priority queue
func NewPriorityQueue ¶
func NewPriorityQueue[T any](comparator PriorityQueueComparator[T]) PriorityQueueInterface[T]
NewPriorityQueue creates a new PriorityQueue with the given comparator.
type RBNode ¶
type RBNode[T any] struct { // contains filtered or unexported fields }
RBNode represents a node in the Red-Black Tree.
type RBTree ¶
type RBTree[T any] struct { // contains filtered or unexported fields }
RBTree represents a Red-Black Tree with a pool for nodes and trees.
func NewRBTree ¶
func NewRBTree[T any](comparator Comparator[T], nodePool *ObjectPool[RBNode[T]], treePool *ObjectPool[RBTree[T]]) *RBTree[T]
NewRBTree creates a new instance of a Red-Black Tree with a custom comparator and node and tree pools.
func (*RBTree[T]) CleanUp ¶
func (tree *RBTree[T]) CleanUp(f func(T))
CleanUpTree resets the tree's properties and returns it to the tree pool.
func (*RBTree[T]) InOrder ¶
func (tree *RBTree[T]) InOrder(f func(T))
InOrder traverses the tree in-order and applies the provided function to each node.
func (*RBTree[T]) Insert ¶
func (tree *RBTree[T]) Insert(value T)
Insert inserts a value into the Red-Black Tree.
func (*RBTree[T]) PrintInOrder ¶
func (tree *RBTree[T]) PrintInOrder()
PrintInOrder is a utility function to print the tree in-order (for debugging).
func (*RBTree[T]) Search ¶
Search looks for a node with the given value in the RBTree and returns true if found.
func (*RBTree[T]) SearchNode ¶
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore is a struct that encapsulates a semaphore pattern for concurrency control.
func NewSemaphore ¶
NewSemaphore creates a new Semaphore with a specified maximum number of concurrent goroutines.
func (*Semaphore) Acquire ¶
func (s *Semaphore) Acquire()
Acquire acquires a semaphore slot. Blocks if no slots are available.
func (*Semaphore) ProcessAndRelease ¶
func (s *Semaphore) ProcessAndRelease(fn func())
ProcessAndRelease processes a given function with arguments and releases the semaphore.
func (*Semaphore) ProcessAndReleaseReflect ¶
func (s *Semaphore) ProcessAndReleaseReflect(fn interface{}, args ...interface{})
ProcessAndReleaseReflect processes a given function with arguments and releases the semaphore.
type TimeIntervalCache ¶
type TimeIntervalCache[T any] struct { // contains filtered or unexported fields }
Define a generic TimeIntervalCache structure with childInterval included
func NewTimeIntervalCache ¶
func NewTimeIntervalCache[T any](s int64, interval int64, defaultValue T, pool *ObjectPool[TimeIntervalCache[T]], cleanupFunc func(T)) *TimeIntervalCache[T]
NewTimeIntervalCache is a generic function to create a new TimeIntervalCache instance with childInterval and cleanup function
func (*TimeIntervalCache[T]) CleanUp ¶
func (dc *TimeIntervalCache[T]) CleanUp()
CleanUp returns the TimeIntervalCache to the pool, invoking the cleanup function for each value
func (*TimeIntervalCache[T]) Get ¶
func (dc *TimeIntervalCache[T]) Get(time int64) T
Get retrieves a value from the TimeIntervalCache based on the time
func (*TimeIntervalCache[T]) GetIfExist ¶
func (dc *TimeIntervalCache[T]) GetIfExist(time int64) T
Get retrieves a value from the TimeIntervalCache based on the time
func (*TimeIntervalCache[T]) IsOutOfIndex ¶
func (dc *TimeIntervalCache[T]) IsOutOfIndex(time int64) bool
IsOutOfIndex checks if the given time is outside the index bounds of the cache
func (*TimeIntervalCache[T]) Set ¶
func (dc *TimeIntervalCache[T]) Set(time int64, s T)
AddInCache adds a value to the TimeIntervalCache
type TimeUtil ¶
func DayTimeFromTimeStamp ¶
func NewTimeUtil ¶
func NewTimeUtilFromFormat ¶
func TimeFromTimeStamp ¶
func (TimeUtil) RFC3339FormatDate ¶
func (TimeUtil) StockFormatDate ¶
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool is a struct that manages a pool of workers to execute tasks concurrently.
func NewWorkerPool ¶
func NewWorkerPool(numWorkers int, maxTasks int) *WorkerPool
NewWorkerPool creates a new WorkerPool with a specified number of workers and a maximum number of tasks in the queue.
func (*WorkerPool) AddTask ¶
func (wp *WorkerPool) AddTask(task Task)
AddTask adds a new task to the worker pool for execution.
func (*WorkerPool) Wait ¶
func (wp *WorkerPool) Wait()
Wait blocks until all tasks have been completed and all workers have stopped.