Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
36b78e8d
Commit
36b78e8d
authored
Mar 16, 2018
by
antirez
Browse files
Aesthetic changes to PR #4749.
parent
7e3c5835
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/hyperloglog.c
View file @
36b78e8d
...
...
@@ -405,7 +405,7 @@ uint64_t MurmurHash64A (const void * key, int len, unsigned int seed) {
#if (BYTE_ORDER == LITTLE_ENDIAN)
#ifdef USE_ALIGNED_ACCESS
memcpy
(
&
k
,
data
,
sizeof
(
uint64_t
));
memcpy
(
&
k
,
data
,
sizeof
(
uint64_t
));
#else
k
=
*
((
uint64_t
*
)
data
);
#endif
...
...
@@ -516,7 +516,7 @@ int hllDenseAdd(uint8_t *registers, unsigned char *ele, size_t elesize) {
}
/* Compute the register histogram in the dense representation. */
void
hllDenseRegHisto
(
uint8_t
*
registers
,
int
*
reg
H
isto
)
{
void
hllDenseRegHisto
(
uint8_t
*
registers
,
int
*
reg
h
isto
)
{
int
j
;
/* Redis default is to use 16384 registers 6 bits each. The code works
...
...
@@ -545,22 +545,22 @@ void hllDenseRegHisto(uint8_t *registers, int* regHisto) {
r14
=
(
r
[
10
]
>>
4
|
r
[
11
]
<<
4
)
&
63
;
r15
=
(
r
[
11
]
>>
2
)
&
63
;
reg
H
isto
[
r0
]
+=
1
;
reg
H
isto
[
r1
]
+=
1
;
reg
H
isto
[
r2
]
+=
1
;
reg
H
isto
[
r3
]
+=
1
;
reg
H
isto
[
r4
]
+=
1
;
reg
H
isto
[
r5
]
+=
1
;
reg
H
isto
[
r6
]
+=
1
;
reg
H
isto
[
r7
]
+=
1
;
reg
H
isto
[
r8
]
+=
1
;
reg
H
isto
[
r9
]
+=
1
;
reg
H
isto
[
r10
]
+=
1
;
reg
H
isto
[
r11
]
+=
1
;
reg
H
isto
[
r12
]
+=
1
;
reg
H
isto
[
r13
]
+=
1
;
reg
H
isto
[
r14
]
+=
1
;
reg
H
isto
[
r15
]
+=
1
;
reg
h
isto
[
r0
]
++
;
reg
h
isto
[
r1
]
++
;
reg
h
isto
[
r2
]
++
;
reg
h
isto
[
r3
]
++
;
reg
h
isto
[
r4
]
++
;
reg
h
isto
[
r5
]
++
;
reg
h
isto
[
r6
]
++
;
reg
h
isto
[
r7
]
++
;
reg
h
isto
[
r8
]
++
;
reg
h
isto
[
r9
]
++
;
reg
h
isto
[
r10
]
++
;
reg
h
isto
[
r11
]
++
;
reg
h
isto
[
r12
]
++
;
reg
h
isto
[
r13
]
++
;
reg
h
isto
[
r14
]
++
;
reg
h
isto
[
r15
]
++
;
r
+=
12
;
}
...
...
@@ -568,7 +568,7 @@ void hllDenseRegHisto(uint8_t *registers, int* regHisto) {
for
(
j
=
0
;
j
<
HLL_REGISTERS
;
j
++
)
{
unsigned
long
reg
;
HLL_DENSE_GET_REGISTER
(
reg
,
registers
,
j
);
reg
H
isto
[
reg
]
+=
1
;
reg
h
isto
[
reg
]
++
;
}
}
}
...
...
@@ -907,7 +907,7 @@ int hllSparseAdd(robj *o, unsigned char *ele, size_t elesize) {
}
/* Compute the register histogram in the sparse representation. */
void
hllSparseRegHisto
(
uint8_t
*
sparse
,
int
sparselen
,
int
*
invalid
,
int
*
reg
H
isto
)
{
void
hllSparseRegHisto
(
uint8_t
*
sparse
,
int
sparselen
,
int
*
invalid
,
int
*
reg
h
isto
)
{
int
idx
=
0
,
runlen
,
regval
;
uint8_t
*
end
=
sparse
+
sparselen
,
*
p
=
sparse
;
...
...
@@ -915,18 +915,18 @@ void hllSparseRegHisto(uint8_t *sparse, int sparselen, int *invalid, int* regHis
if
(
HLL_SPARSE_IS_ZERO
(
p
))
{
runlen
=
HLL_SPARSE_ZERO_LEN
(
p
);
idx
+=
runlen
;
reg
H
isto
[
0
]
+=
runlen
;
reg
h
isto
[
0
]
+=
runlen
;
p
++
;
}
else
if
(
HLL_SPARSE_IS_XZERO
(
p
))
{
runlen
=
HLL_SPARSE_XZERO_LEN
(
p
);
idx
+=
runlen
;
reg
H
isto
[
0
]
+=
runlen
;
reg
h
isto
[
0
]
+=
runlen
;
p
+=
2
;
}
else
{
runlen
=
HLL_SPARSE_VAL_LEN
(
p
);
regval
=
HLL_SPARSE_VAL_VALUE
(
p
);
idx
+=
runlen
;
reg
H
isto
[
regval
]
+=
runlen
;
reg
h
isto
[
regval
]
+=
runlen
;
p
++
;
}
}
...
...
@@ -941,24 +941,24 @@ void hllSparseRegHisto(uint8_t *sparse, int sparselen, int *invalid, int* regHis
/* Implements the register histogram calculation for uint8_t data type
* which is only used internally as speedup for PFCOUNT with multiple keys. */
void
hllRawRegHisto
(
uint8_t
*
registers
,
int
*
reg
H
isto
)
{
void
hllRawRegHisto
(
uint8_t
*
registers
,
int
*
reg
h
isto
)
{
uint64_t
*
word
=
(
uint64_t
*
)
registers
;
uint8_t
*
bytes
;
int
j
;
for
(
j
=
0
;
j
<
HLL_REGISTERS
/
8
;
j
++
)
{
if
(
*
word
==
0
)
{
reg
H
isto
[
0
]
+=
8
;
reg
h
isto
[
0
]
+=
8
;
}
else
{
bytes
=
(
uint8_t
*
)
word
;
reg
H
isto
[
bytes
[
0
]]
+=
1
;
reg
H
isto
[
bytes
[
1
]]
+=
1
;
reg
H
isto
[
bytes
[
2
]]
+=
1
;
reg
H
isto
[
bytes
[
3
]]
+=
1
;
reg
H
isto
[
bytes
[
4
]]
+=
1
;
reg
H
isto
[
bytes
[
5
]]
+=
1
;
reg
H
isto
[
bytes
[
6
]]
+=
1
;
reg
H
isto
[
bytes
[
7
]]
+=
1
;
reg
h
isto
[
bytes
[
0
]]
++
;
reg
h
isto
[
bytes
[
1
]]
++
;
reg
h
isto
[
bytes
[
2
]]
++
;
reg
h
isto
[
bytes
[
3
]]
++
;
reg
h
isto
[
bytes
[
4
]]
++
;
reg
h
isto
[
bytes
[
5
]]
++
;
reg
h
isto
[
bytes
[
6
]]
++
;
reg
h
isto
[
bytes
[
7
]]
++
;
}
word
++
;
}
...
...
@@ -1013,16 +1013,16 @@ uint64_t hllCount(struct hllhdr *hdr, int *invalid) {
double
m
=
HLL_REGISTERS
;
double
E
;
int
j
;
int
reg
H
isto
[
HLL_Q
+
2
]
=
{
0
};
int
reg
h
isto
[
HLL_Q
+
2
]
=
{
0
};
/* Compute register histogram */
if
(
hdr
->
encoding
==
HLL_DENSE
)
{
hllDenseRegHisto
(
hdr
->
registers
,
reg
H
isto
);
hllDenseRegHisto
(
hdr
->
registers
,
reg
h
isto
);
}
else
if
(
hdr
->
encoding
==
HLL_SPARSE
)
{
hllSparseRegHisto
(
hdr
->
registers
,
sdslen
((
sds
)
hdr
)
-
HLL_HDR_SIZE
,
invalid
,
reg
H
isto
);
sdslen
((
sds
)
hdr
)
-
HLL_HDR_SIZE
,
invalid
,
reg
h
isto
);
}
else
if
(
hdr
->
encoding
==
HLL_RAW
)
{
hllRawRegHisto
(
hdr
->
registers
,
reg
H
isto
);
hllRawRegHisto
(
hdr
->
registers
,
reg
h
isto
);
}
else
{
serverPanic
(
"Unknown HyperLogLog encoding in hllCount()"
);
}
...
...
@@ -1030,12 +1030,12 @@ uint64_t hllCount(struct hllhdr *hdr, int *invalid) {
/* Estimate cardinality form register histogram. See:
* "New cardinality estimation algorithms for HyperLogLog sketches"
* Otmar Ertl, arXiv:1702.01284 */
double
z
=
m
*
hllTau
((
m
-
reg
H
isto
[
HLL_Q
+
1
])
/
(
double
)
m
);
double
z
=
m
*
hllTau
((
m
-
reg
h
isto
[
HLL_Q
+
1
])
/
(
double
)
m
);
for
(
j
=
HLL_Q
;
j
>=
1
;
--
j
)
{
z
+=
reg
H
isto
[
j
];
z
+=
reg
h
isto
[
j
];
z
*=
0
.
5
;
}
z
+=
m
*
hllSigma
(
reg
H
isto
[
0
]
/
(
double
)
m
);
z
+=
m
*
hllSigma
(
reg
h
isto
[
0
]
/
(
double
)
m
);
E
=
llroundl
(
HLL_ALPHA_INF
*
m
*
m
/
z
);
return
(
uint64_t
)
E
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment