Documentation ¶
Overview ¶
Copyright (c) 2015, RetailNext, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hyperloglog.c - Redis HyperLogLog probabilistic cardinality approximation. * This file implements the algorithm and the exported Redis commands. * * Copyright (c) 2014, Salvatore Sanfilippo <antirez at gmail dot com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Redis nor the names of its contributors may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE.
Index ¶
- Constants
- Variables
- func Add(p, tmp []byte, reg Register, count uint8) (pout, tmpout []byte, added bool, err error)
- func Count(p []byte) (int, error)
- func DecodeRetailNextHeader(p []byte) (sparse bool, bpr int, err error)
- func DenseSum(p []byte) (E float64, ez int)
- func EncodePipelineFormat(b, p []byte) ([]byte, error)
- func Init(p []byte) []byte
- func InitDense(p []byte) []byte
- func IsRedisFormat(p []byte) bool
- func MurmurSum64(data []byte) uint64
- func Reduce(p, q, tmp []byte) (pout, tmpout []byte, err error)
- func SparseSum(p []byte) (E float64, ez int, err error)
- func SparseToDense(p, tmp []byte) (pout, tmpout []byte, err error)
- type Register
Constants ¶
const ( PipelineDenseDirty = 'd' PipelineDenseClean = 'D' PipelineSparseClean = 'S' PipelineSparseDirty = 's' )
const ( P = 14 // The greater P is, the smaller the error. Registers = 1 << P // With P=14, 16384 registers. CountBits = 6 // Enough to count up to 63 leading zeros. CountMax = (1 << CountBits) - 1 HeaderSize = 16 DenseRegistersSize = (Registers*CountBits+7)/8 + 1 + HeaderSize )
const (
HeaderSizeRetailNext = 15
)
Variables ¶
var PE [64]float64
Functions ¶
func Add ¶
Add folds |reg| and |count| into the HLL encoded by |p|. |tmp| may be used to reduce required allocation.
func DecodeRetailNextHeader ¶
DecodeRetailNextHeader verifies that |p| is a serialized RetailNext HLL, and extracts key properties of the representation.
func DenseSum ¶
Compute SUM(2^-reg) in the dense representation. * PE is an array with a pre-computer table of values 2^-reg indexed by reg. * As a side effect the integer pointed by 'ezp' is set to the number * of zero registers.
func EncodePipelineFormat ¶
EncodePipelineFormat appends the HLL |p|, in Redis format, to |b| as a PipelineDB-formatted HLL. The representations share the same register wire format, but have slightly differing headers.
func IsRedisFormat ¶
IsRedisFormat returns whether the HLL is in the standard Redis wire format.
func MurmurSum64 ¶
This is a port of MurmurHash3_x64_128 from MurmurHash3.cpp
func Reduce ¶
Reduce reduces HLL |q| into HLL |p|. |tmp| may be used to reduce memory allocation. |p| and |tmp| may be modified and are returned. |q| is never modified.
func SparseToDense ¶
Types ¶
type Register ¶
type Register uint
func RegisterRhoRedis ¶
RegisterRhoRedis returns the Register and rho (count) for |hash| with an identical implementation to Redis.
func RegisterRhoRetailNext ¶
RegisterRhoRedis returns the Register and rho (count) for |hash| with an identical implementation to the RetailNext HLLPP implementation.