Documentation

Overview

    Package card provides cardinality estimation functions.

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    func RegisterHash

    func RegisterHash(fn interface{})

      RegisterHash registers a function that returns a new hash.Hash32 or hash.Hash64 to the name of the type implementing the interface. The value of fn must be a func() hash.Hash32 or func() hash.Hash64, otherwise RegisterHash will panic. RegisterHash will panic if there is not a unique mapping from the name to the returned type.

      Types

      type HyperLogLog32

      type HyperLogLog32 struct {
      	// contains filtered or unexported fields
      }

        HyperLogLog32 is implements cardinality estimation according to the HyperLogLog algorithm described in Analysis of Algorithms, pp127–146.

        func NewHyperLogLog32

        func NewHyperLogLog32(prec int, h hash.Hash32) (*HyperLogLog32, error)

          NewHyperLogLog32 returns a new HyperLogLog32 sketch. The value of prec must be in the range [4, 32]. NewHyperLogLog32 will allocate a byte slice that is 2^prec long.

          func (*HyperLogLog32) Count

          func (h *HyperLogLog32) Count() float64

            Count returns an estimate of the cardinality of the set of items written the receiver.

            func (*HyperLogLog32) MarshalBinary

            func (h *HyperLogLog32) MarshalBinary() ([]byte, error)

              MarshalBinary marshals the sketch in the receiver. It encodes the name of the hash function, the precision of the sketch and the sketch data. The receiver must have a non-nil hash function.

              func (*HyperLogLog32) Reset

              func (h *HyperLogLog32) Reset()

                Reset clears the receiver's registers allowing it to be reused. Reset does not alter the precision of the receiver or the hash function that is used.

                func (*HyperLogLog32) SetHash

                func (h *HyperLogLog32) SetHash(fn hash.Hash32) error

                  SetHash sets the hash function of the receiver if it is nil. SetHash will return an error if it is called on a receiver with a non-nil hash function.

                  func (*HyperLogLog32) Union

                  func (h *HyperLogLog32) Union(a, b *HyperLogLog32) error

                    Union places the union of the sketches in a and b into the receiver. Union will return an error if the precisions or hash functions of a and b do not match or if the receiver has a hash function that is set and does not match those of a and b. Hash functions provided by hash.Hash32 implementations x and y match when reflect.TypeOf(x) == reflect.TypeOf(y).

                    If the receiver does not have a set hash function, it can be set after a call to Union with the SetHash method.

                    func (*HyperLogLog32) UnmarshalBinary

                    func (h *HyperLogLog32) UnmarshalBinary(b []byte) error

                      UnmarshalBinary unmarshals the binary representation of a sketch into the receiver. The precision of the receiver will be set after return. The receiver must have a non-nil hash function value that is the same type as the one that was stored in the binary data.

                      func (*HyperLogLog32) Write

                      func (h *HyperLogLog32) Write(b []byte) (int, error)

                        Write notes the data in b as a single observation into the sketch held by the receiver.

                        Write satisfies the io.Writer interface. If the hash.Hash32 type passed to NewHyperLogLog32 or SetHash satisfies the hash.Hash contract, Write will always return a nil error.

                        type HyperLogLog64

                        type HyperLogLog64 struct {
                        	// contains filtered or unexported fields
                        }

                          HyperLogLog64 is implements cardinality estimation according to the HyperLogLog algorithm described in Analysis of Algorithms, pp127–146.

                          func NewHyperLogLog64

                          func NewHyperLogLog64(prec int, h hash.Hash64) (*HyperLogLog64, error)

                            NewHyperLogLog64 returns a new HyperLogLog64 sketch. The value of prec must be in the range [4, 64]. NewHyperLogLog64 will allocate a byte slice that is 2^prec long.

                            func (*HyperLogLog64) Count

                            func (h *HyperLogLog64) Count() float64

                              Count returns an estimate of the cardinality of the set of items written the receiver.

                              func (*HyperLogLog64) MarshalBinary

                              func (h *HyperLogLog64) MarshalBinary() ([]byte, error)

                                MarshalBinary marshals the sketch in the receiver. It encodes the name of the hash function, the precision of the sketch and the sketch data. The receiver must have a non-nil hash function.

                                func (*HyperLogLog64) Reset

                                func (h *HyperLogLog64) Reset()

                                  Reset clears the receiver's registers allowing it to be reused. Reset does not alter the precision of the receiver or the hash function that is used.

                                  func (*HyperLogLog64) SetHash

                                  func (h *HyperLogLog64) SetHash(fn hash.Hash64) error

                                    SetHash sets the hash function of the receiver if it is nil. SetHash will return an error if it is called on a receiver with a non-nil hash function.

                                    func (*HyperLogLog64) Union

                                    func (h *HyperLogLog64) Union(a, b *HyperLogLog64) error

                                      Union places the union of the sketches in a and b into the receiver. Union will return an error if the precisions or hash functions of a and b do not match or if the receiver has a hash function that is set and does not match those of a and b. Hash functions provided by hash.Hash64 implementations x and y match when reflect.TypeOf(x) == reflect.TypeOf(y).

                                      If the receiver does not have a set hash function, it can be set after a call to Union with the SetHash method.

                                      func (*HyperLogLog64) UnmarshalBinary

                                      func (h *HyperLogLog64) UnmarshalBinary(b []byte) error

                                        UnmarshalBinary unmarshals the binary representation of a sketch into the receiver. The precision of the receiver will be set after return. The receiver must have a non-nil hash function value that is the same type as the one that was stored in the binary data.

                                        func (*HyperLogLog64) Write

                                        func (h *HyperLogLog64) Write(b []byte) (int, error)

                                          Write notes the data in b as a single observation into the sketch held by the receiver.

                                          Write satisfies the io.Writer interface. If the hash.Hash64 type passed to NewHyperLogLog64 or SetHash satisfies the hash.Hash contract, Write will always return a nil error.