Documentation
¶
Overview ¶
Example ¶
duration := time.Duration(720 * time.Hour) // 720 hours range
unit := time.Hour
// Create sketch queryable with
// duation = 720 hours range
// unit = 1 hour
// width per sketch = 2^9
// depth per sketch = 8
// alpha = 1.004 (used for emphasizing and de-emphasizing)
sks := NewSketches(duration, unit, 9, 7, 1.004)
item := []byte("foo")
t1 := time.Date(2017, 06, 03, 0, 0, 0, 0, time.UTC)
t2 := t1.Add(time.Hour)
t3 := t2.Add(time.Hour)
t4 := t3.Add(time.Hour)
count1 := uint64(1337)
count2 := uint64(100000)
// Update item for given timestamps
sks.Insert(item, t1, count1)
sks.Insert(item, t3, count2)
// Estimate count of item within time range [t1, t2]
got, _ := sks.Estimate(item, t1, t2)
fmt.Printf("Expected count for \"%s\" in timerange [%v, %v] to be %d, got %d\n",
string(item), t1.Format(time.Kitchen), t2.Format(time.Kitchen), count1, got)
// Estimate count of item within time range [t1, t3]
got, _ = sks.Estimate(item, t1, t3)
fmt.Printf("Expected count for \"%s\" in timerange [%v, %v] to be %d, got %d\n",
string(item), t1.Format(time.Kitchen), t3.Format(time.Kitchen), count1+count2, got)
// Estimate count of item within time range [t1, t3]
got, _ = sks.Estimate(item, t3, t4)
fmt.Printf("Expected count for \"%s\" in timerange [%v, %v] to be %d, got %d\n",
string(item), t3.Format(time.Kitchen), t4.Format(time.Kitchen), count2, got)
Output: Expected count for "foo" in timerange [12:00AM, 1:00AM] to be 1337, got 1337 Expected count for "foo" in timerange [12:00AM, 2:00AM] to be 101337, got 101337 Expected count for "foo" in timerange [2:00AM, 3:00AM] to be 100000, got 100000
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ACMS ¶
type ACMS struct {
// contains filtered or unexported fields
}
ACMS is a simple count-min-sketch imeplementation with a exp based pre-emphasis and de-emphasis of values
func NewACMS ¶
NewACMS returns a Sketch of width 2^w and depth d for a given alpha the alpha is ussed to pre-emphasis and de-emphasis the counters using alpha^timestamp
type Sketches ¶
type Sketches struct {
// contains filtered or unexported fields
}
Sketches represents an set of Adaptive Count-Min Sketch algorithm (Ada-CMS), which is just CMS but with the update and query mechanisms adapted to use the pre-emphasis and de-emphasis mechanism.
func NewSketches ¶
NewSketches returns an adaptive Sketch (representing multiple Adaptive Count-Min Sketches) with: maxDuration: specifies the max queriable range timeUnit: degines the unit of measurment, ns, ms, s, etc... w: width of CMS is 2^w d: depth of CMS alpha: ussed to pre-emphasis and de-emphasis the counters using alpha^timestamp
func (*Sketches) Estimate ¶
Estimate returns the count of an item within a given timerange [start, end], if timerange > maxDuration return error