Documentation ¶
Overview ¶
Package countminsketch is an implementation of Count-Min Sketch in Golang.
http://github.com/shenwei356/countmin/
The code is deeply inspired by an implementation of Bloom filters in golang, [bloom](https://github.com/willf/bloom).
Index ¶
- type CountMinSketch
- func (s *CountMinSketch) D() uint
- func (s *CountMinSketch) Estimate(key []byte) uint64
- func (s *CountMinSketch) EstimateString(key string) uint64
- func (s *CountMinSketch) GobDecode(data []byte) error
- func (s *CountMinSketch) GobEncode() ([]byte, error)
- func (s *CountMinSketch) MarshalJSON() ([]byte, error)
- func (s *CountMinSketch) Merge(other *CountMinSketch) error
- func (s *CountMinSketch) ReadFrom(stream io.Reader) (int64, error)
- func (s *CountMinSketch) ReadFromFile(file string) (int64, error)
- func (s *CountMinSketch) UnmarshalJSON(data []byte) error
- func (s *CountMinSketch) Update(key []byte, count uint64)
- func (s *CountMinSketch) UpdateString(key string, count uint64)
- func (s *CountMinSketch) W() uint
- func (s *CountMinSketch) WriteTo(stream io.Writer) (int64, error)
- func (s *CountMinSketch) WriteToFile(file string) (int64, error)
- type CountMinSketchJSON
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CountMinSketch ¶
type CountMinSketch struct {
// contains filtered or unexported fields
}
CountMinSketch struct. d is the number of hashing functions, w is the size of every hash table. count, a matrix, is used to store the count. uint is used to store count, the maximum count is 1<<32-1 in 32 bit OS, and 1<<64-1 in 64 bit OS.
func New ¶
func New(d uint, w uint) (s *CountMinSketch, err error)
New creates a new Count-Min Sketch with _d_ hashing functions and _w_ hash value range
func NewFromFile ¶
func NewFromFile(file string) (*CountMinSketch, error)
NewFromFile creates a new Count-Min Sketch from dumpped file
func NewWithEstimates ¶
func NewWithEstimates(epsilon, delta float64) (*CountMinSketch, error)
NewWithEstimates creates a new Count-Min Sketch with given error rate and confidence. Accuracy guarantees will be made in terms of a pair of user specified parameters, ε and δ, meaning that the error in answering a query is within a factor of ε with probability δ
func (*CountMinSketch) D ¶
func (s *CountMinSketch) D() uint
D returns the number of hashing functions
func (*CountMinSketch) Estimate ¶
func (s *CountMinSketch) Estimate(key []byte) uint64
Estimate the frequency of a key. It is point query.
func (*CountMinSketch) EstimateString ¶
func (s *CountMinSketch) EstimateString(key string) uint64
EstimateString estimate the frequency of a key of string
func (*CountMinSketch) GobDecode ¶
func (s *CountMinSketch) GobDecode(data []byte) error
GobDecode implements gob.GobDecoder interface.
func (*CountMinSketch) GobEncode ¶
func (s *CountMinSketch) GobEncode() ([]byte, error)
GobEncode implements gob.GobEncoder interface.
func (*CountMinSketch) MarshalJSON ¶
func (s *CountMinSketch) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler interface. Based on https://github.com/willf/bloom/blob/master/bloom.go
func (*CountMinSketch) Merge ¶
func (s *CountMinSketch) Merge(other *CountMinSketch) error
Merge combines this CountMinSketch with another one
func (*CountMinSketch) ReadFrom ¶
func (s *CountMinSketch) ReadFrom(stream io.Reader) (int64, error)
ReadFrom a binary representation of the CountMinSketch from an i/o stream. Based on https://github.com/willf/bloom/blob/master/bloom.go
func (*CountMinSketch) ReadFromFile ¶
func (s *CountMinSketch) ReadFromFile(file string) (int64, error)
ReadFromFile reads Count-Min Sketch from file
func (*CountMinSketch) UnmarshalJSON ¶
func (s *CountMinSketch) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler interface. Based on https://github.com/willf/bloom/blob/master/bloom.go
func (*CountMinSketch) Update ¶
func (s *CountMinSketch) Update(key []byte, count uint64)
Update the frequency of a key
func (*CountMinSketch) UpdateString ¶
func (s *CountMinSketch) UpdateString(key string, count uint64)
UpdateString updates the frequency of a key
func (*CountMinSketch) W ¶
func (s *CountMinSketch) W() uint
W returns the size of hashing functions
func (*CountMinSketch) WriteTo ¶
func (s *CountMinSketch) WriteTo(stream io.Writer) (int64, error)
WriteTo writes a binary representation of the CountMinSketch to an i/o stream. Based on https://github.com/willf/bloom/blob/master/bloom.go
func (*CountMinSketch) WriteToFile ¶
func (s *CountMinSketch) WriteToFile(file string) (int64, error)
WriteToFile writes the Count-Min Sketch to file
type CountMinSketchJSON ¶
type CountMinSketchJSON struct { D uint `json:"d"` W uint `json:"w"` Count [][]uint64 `json:"count"` }
CountMinSketchJSON is the JSON struct of CountMinSketch for marshal and unmarshal