Documentation
¶
Overview ¶
Copyright 2018-2019 The logrange Authors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- type CLElement
- type Lru
- func (l *Lru) Clear(cb bool)
- func (l *Lru) Delete(k interface{})
- func (l *Lru) DeleteNoCallback(k interface{})
- func (l *Lru) Get(k interface{}) *LruValue
- func (l *Lru) GetData() map[interface{}]interface{}
- func (l *Lru) Iterate(f LruCallback)
- func (l *Lru) Len() int
- func (l *Lru) Peek(k interface{}) *LruValue
- func (l *Lru) Put(k, v interface{}, size int64)
- func (l *Lru) Size() int64
- func (l *Lru) SweepByTime() time.Time
- type LruCallback
- type LruDeleteCallback
- type LruValue
- type RingBuffer
- func (rb *RingBuffer) AdvanceHead() interface{}
- func (rb *RingBuffer) AdvanceTail() interface{}
- func (rb *RingBuffer) At(i int) interface{}
- func (rb *RingBuffer) Capacity() int
- func (rb *RingBuffer) Clear()
- func (rb *RingBuffer) Head() interface{}
- func (rb *RingBuffer) IsFull() bool
- func (rb *RingBuffer) Len() int
- func (rb *RingBuffer) Push(v interface{}) interface{}
- func (rb *RingBuffer) Set(i int, v interface{})
- func (rb *RingBuffer) Tail() interface{}
- type Timeseries
- type TsClockNowF
- type TsInt
- type TsNewValueF
- type TsValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CLElement ¶
type CLElement struct {
Val interface{}
// contains filtered or unexported fields
}
CLElement struct describes a circular list element. It contains references to previous and next elements. By default every non-nil element forms a circular list which contains only one element, which refers to itself.
func NewCLElement ¶
func NewCLElement() *CLElement
NewCLElement returns new CLElement which refers to itself
func (*CLElement) Len ¶
Len returns number of elements in the Circular list. It has O(N) complexity.
type Lru ¶
type Lru struct {
// contains filtered or unexported fields
}
Lru is "Least Recently Used" container, which keeps key-value pairs in it. Lru supports auto-removing discipline which can be triggered by the container size, an element expiration timeout or both. It sorts stored elements by their recently used time, so most recently used are stored at head of the list, but auto-removing procedure works from the bottom, so it removes longest not-used element first.
Lru should be properly synchronized in case of it is used from multiple goroutines.
func NewLru ¶
func NewLru(maxSize int64, to time.Duration, cback LruDeleteCallback) *Lru
NewLru creates new Lru container with maximum size maxSize, and maximum time 'to' an element can stay in the cache. cback is a function which is invoked when an element is pulled out of the cache. It can be nil
Timeout 'to' could be 0, what means don't use it at all
func (*Lru) Clear ¶
Clear removes all elements from the container. It will notify listeners about any element which is being deleted if cb == true.
func (*Lru) Delete ¶
func (l *Lru) Delete(k interface{})
Delete removes the value by its key 'k' from the Lru. If the container has callbacks, it will notify listeners about the operation
func (*Lru) DeleteNoCallback ¶
func (l *Lru) DeleteNoCallback(k interface{})
DeleteNoCallback removes the value by its key 'k' from the Lru. No notifications will be done.
func (*Lru) Get ¶
Get returns the *LruValue by its key, and removes it from the collection. The resulted value could be valid till ANY other call to the Lru, and its value is undefined after that. Please use the value as soon as you get it and never cache or pass it through to other functions.
func (*Lru) GetData ¶
func (l *Lru) GetData() map[interface{}]interface{}
GetData returns underlying container data for the LRU. The returned value is a key-value map
func (*Lru) Iterate ¶
func (l *Lru) Iterate(f LruCallback)
Iterate is the container visitor which walks over the elements in LRU order. It calls f() for every key-value pair and continues until the f() returns false, or all elements are visited.
Note: the modifications of the container must not allowed in the f. It means f MUST not use the Lru functions.
func (*Lru) Peek ¶
Peek works the same way like Get() does, but it doesn't remove the element from the Lru
func (*Lru) Put ¶
Put places new value v with the key k, considering the size of the element as 'size'. Some elements can be pull out from the Lru due to their timeouts or if the collection size will exceed the max value.
func (*Lru) SweepByTime ¶
SweepByTime walks trhough the container values and removes that are expired
type LruCallback ¶
type LruCallback func(k, v interface{}) bool
type LruDeleteCallback ¶
type LruDeleteCallback func(k, v interface{})
type LruValue ¶
type LruValue struct {
// contains filtered or unexported fields
}
LruValue represents a value, stored in Lru. The object is returned by Lru.Get() function.
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer - the ring buffer with fixed capacity. The container has head and tail. It provides operations that allows to manipulate the data stored in the buffer.
Handle with caution! The buffer doesn't free elements, and doesn't nilling them intentionally. It was made with an intention to minimize memory allocations for the stored elements. It is the buffer's user responsibility to free and nillify stored values.
func NewRingBuffer ¶
func NewRingBuffer(size int) *RingBuffer
NewRingBuffer - returns new ring buffer with size elements reserved
func (*RingBuffer) AdvanceHead ¶
func (rb *RingBuffer) AdvanceHead() interface{}
AdvanceHead - advances head and reduce the buffer size to 1 (head) element. It returns the element, which was at head, before the operation
func (*RingBuffer) AdvanceTail ¶
func (rb *RingBuffer) AdvanceTail() interface{}
AdvanceTail - moves the tail and increases the current buffer size by 1. if the buffer size reaches the maximum capacity, it will return head element, moving the head and tail both to 1 position.
func (*RingBuffer) At ¶
func (rb *RingBuffer) At(i int) interface{}
At - returns element at the index i, countin from the head. Will panic if the index is out of bounds
func (*RingBuffer) Capacity ¶
func (rb *RingBuffer) Capacity() int
Capacity - returns the buffer capacity
func (*RingBuffer) Head ¶
func (rb *RingBuffer) Head() interface{}
Head - returns head's element. Will panic if size of the RingBuffer is 0
func (*RingBuffer) IsFull ¶
func (rb *RingBuffer) IsFull() bool
IsFull - returns true if the buffer is full Len() == Capacity()
func (*RingBuffer) Push ¶
func (rb *RingBuffer) Push(v interface{}) interface{}
Push - places value v at the tail. It will increase the buffer size, or pops head element if the buffer's capacity is reached. The previos element stored at the new tail position is returned. After the operation tail points to the new value v.
func (*RingBuffer) Set ¶
func (rb *RingBuffer) Set(i int, v interface{})
Set - assign value v for the element i, counting from the head.
func (*RingBuffer) Tail ¶
func (rb *RingBuffer) Tail() interface{}
Tail - returns tail's element. Will panic if size of the RingBuffer is 0
type Timeseries ¶
type Timeseries struct {
// contains filtered or unexported fields
}
Timeseries is a structure, which keeps time-series in the number of chained buckets. This is a time-sliding window which can be used for smoothing out an observed scalar value.
func NewTimeseries ¶
func NewTimeseries(bktDur, tsDur time.Duration, newValF TsNewValueF) *Timeseries
NewTimeseries same as NewTimeseriesWithClock, but provides system time.Now() for discovering current time.
func NewTimeseriesWithClock ¶
func NewTimeseriesWithClock(bktDur, tsDur time.Duration, newValF TsNewValueF, clck TsClockNowF) *Timeseries
NewTimeseriesWithClock constructs new Timeseries value. Expects to receive the bucket size(bktDur in time duration), the time-series in time duration in the tsDur parameter, the newValF allows to create new scalar values and the clck is a function which allows to discover current time
func (*Timeseries) Add ¶
func (ts *Timeseries) Add(val TsValue)
func (*Timeseries) StartTime ¶
func (ts *Timeseries) StartTime() time.Time
func (*Timeseries) Total ¶
func (ts *Timeseries) Total() TsValue
type TsClockNowF ¶
TsClockNowF a function whic returns current time
type TsNewValueF ¶
type TsNewValueF func() TsValue
TsNewValueF a function which constructs a TsValue