提交 2ee2bec2 编写于 作者: A antirez

HyperLogLog: make API use the P prefix in honor of Philippe Flajolet.

上级 1e90c006
...@@ -435,8 +435,8 @@ uint64_t hllCount(uint8_t *registers) { ...@@ -435,8 +435,8 @@ uint64_t hllCount(uint8_t *registers) {
/* ========================== HyperLogLog commands ========================== */ /* ========================== HyperLogLog commands ========================== */
/* HLLADD var ele ele ele ... ele => :0 or :1 */ /* PADD var ele ele ele ... ele => :0 or :1 */
void hllAddCommand(redisClient *c) { void paddCommand(redisClient *c) {
robj *o = lookupKeyWrite(c->db,c->argv[1]); robj *o = lookupKeyWrite(c->db,c->argv[1]);
uint8_t *registers; uint8_t *registers;
int updated = 0, j; int updated = 0, j;
...@@ -482,8 +482,8 @@ void hllAddCommand(redisClient *c) { ...@@ -482,8 +482,8 @@ void hllAddCommand(redisClient *c) {
addReply(c, updated ? shared.cone : shared.czero); addReply(c, updated ? shared.cone : shared.czero);
} }
/* HLLCOUNT var -> approximated cardinality of set. */ /* PCOUNT var -> approximated cardinality of set. */
void hllCountCommand(redisClient *c) { void pcountCommand(redisClient *c) {
robj *o = lookupKeyRead(c->db,c->argv[1]); robj *o = lookupKeyRead(c->db,c->argv[1]);
uint8_t *registers; uint8_t *registers;
uint64_t card; uint64_t card;
...@@ -540,8 +540,8 @@ void hllCountCommand(redisClient *c) { ...@@ -540,8 +540,8 @@ void hllCountCommand(redisClient *c) {
} }
} }
/* HLLMERGE dest src1 src2 src3 ... srcN => OK */ /* PMERGE dest src1 src2 src3 ... srcN => OK */
void hllMergeCommand(redisClient *c) { void pmergeCommand(redisClient *c) {
uint8_t max[REDIS_HLL_REGISTERS]; uint8_t max[REDIS_HLL_REGISTERS];
uint8_t *registers; uint8_t *registers;
int j, i; int j, i;
...@@ -614,7 +614,7 @@ void hllMergeCommand(redisClient *c) { ...@@ -614,7 +614,7 @@ void hllMergeCommand(redisClient *c) {
* the correct value to be retained and not affect adjacent values. */ * the correct value to be retained and not affect adjacent values. */
#define REDIS_HLL_TEST_CYCLES 1000 #define REDIS_HLL_TEST_CYCLES 1000
void hllSelftestCommand(redisClient *c) { void pselftestCommand(redisClient *c) {
int j, i; int j, i;
sds bitcounters = sdsnewlen(NULL,REDIS_HLL_SIZE); sds bitcounters = sdsnewlen(NULL,REDIS_HLL_SIZE);
uint8_t bytecounters[REDIS_HLL_REGISTERS]; uint8_t bytecounters[REDIS_HLL_REGISTERS];
......
...@@ -259,10 +259,10 @@ struct redisCommand redisCommandTable[] = { ...@@ -259,10 +259,10 @@ struct redisCommand redisCommandTable[] = {
{"bitop",bitopCommand,-4,"wm",0,NULL,2,-1,1,0,0}, {"bitop",bitopCommand,-4,"wm",0,NULL,2,-1,1,0,0},
{"bitcount",bitcountCommand,-2,"r",0,NULL,1,1,1,0,0}, {"bitcount",bitcountCommand,-2,"r",0,NULL,1,1,1,0,0},
{"bitpos",bitposCommand,-3,"r",0,NULL,1,1,1,0,0}, {"bitpos",bitposCommand,-3,"r",0,NULL,1,1,1,0,0},
{"hllselftest",hllSelftestCommand,1,"r",0,NULL,0,0,0,0,0}, {"pselftest",pselftestCommand,1,"r",0,NULL,0,0,0,0,0},
{"hlladd",hllAddCommand,-2,"wm",0,NULL,1,1,1,0,0}, {"padd",paddCommand,-2,"wm",0,NULL,1,1,1,0,0},
{"hllcount",hllCountCommand,2,"w",0,NULL,1,1,1,0,0}, {"pcount",pcountCommand,2,"w",0,NULL,1,1,1,0,0},
{"hllmerge",hllMergeCommand,-2,"wm",0,NULL,1,-1,1,0,0} {"pmerge",pmergeCommand,-2,"wm",0,NULL,1,-1,1,0,0}
}; };
/*============================ Utility functions ============================ */ /*============================ Utility functions ============================ */
......
...@@ -1351,10 +1351,10 @@ void bitopCommand(redisClient *c); ...@@ -1351,10 +1351,10 @@ void bitopCommand(redisClient *c);
void bitcountCommand(redisClient *c); void bitcountCommand(redisClient *c);
void bitposCommand(redisClient *c); void bitposCommand(redisClient *c);
void replconfCommand(redisClient *c); void replconfCommand(redisClient *c);
void hllSelftestCommand(redisClient *c); void pselftestCommand(redisClient *c);
void hllAddCommand(redisClient *c); void paddCommand(redisClient *c);
void hllCountCommand(redisClient *c); void pcountCommand(redisClient *c);
void hllMergeCommand(redisClient *c); void pmergeCommand(redisClient *c);
#if defined(__GNUC__) #if defined(__GNUC__)
void *calloc(size_t count, size_t size) __attribute__ ((deprecated)); void *calloc(size_t count, size_t size) __attribute__ ((deprecated));
......
...@@ -18,9 +18,9 @@ while true do ...@@ -18,9 +18,9 @@ while true do
elements << ele elements << ele
i += 1 i += 1
} }
r.hlladd('hll',*elements) r.padd('hll',*elements)
} }
approx = r.hllcount('hll') approx = r.pcount('hll')
abs_err = (approx-i).abs abs_err = (approx-i).abs
rel_err = 100.to_f*abs_err/i rel_err = 100.to_f*abs_err/i
puts "#{i} vs #{approx}: #{rel_err}%" puts "#{i} vs #{approx}: #{rel_err}%"
......
...@@ -30,9 +30,9 @@ def run_experiment(r,seed,max,step) ...@@ -30,9 +30,9 @@ def run_experiment(r,seed,max,step)
elements << ele elements << ele
i += 1 i += 1
} }
r.hlladd('hll',*elements) r.padd('hll',*elements)
} }
approx = r.hllcount('hll') approx = r.pcount('hll')
err = approx-i err = approx-i
rel_err = 100.to_f*err/i rel_err = 100.to_f*err/i
samples << [i,rel_err] samples << [i,rel_err]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册