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
d433ebc6
Commit
d433ebc6
authored
Sep 16, 2010
by
Pieter Noordhuis
Browse files
Finished code for sorted set memory efficiency
parent
25bb8a44
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/rdb.c
View file @
d433ebc6
...
@@ -730,13 +730,14 @@ robj *rdbLoadObject(int type, FILE *fp) {
...
@@ -730,13 +730,14 @@ robj *rdbLoadObject(int type, FILE *fp) {
/* Load every single element of the list/set */
/* Load every single element of the list/set */
while
(
zsetlen
--
)
{
while
(
zsetlen
--
)
{
robj
*
ele
;
robj
*
ele
;
double
*
score
=
zmalloc
(
sizeof
(
double
));
double
score
;
zskiplistNode
*
znode
;
if
((
ele
=
rdbLoadEncodedStringObject
(
fp
))
==
NULL
)
return
NULL
;
if
((
ele
=
rdbLoadEncodedStringObject
(
fp
))
==
NULL
)
return
NULL
;
ele
=
tryObjectEncoding
(
ele
);
ele
=
tryObjectEncoding
(
ele
);
if
(
rdbLoadDoubleValue
(
fp
,
score
)
==
-
1
)
return
NULL
;
if
(
rdbLoadDoubleValue
(
fp
,
&
score
)
==
-
1
)
return
NULL
;
dictAdd
(
zs
->
dict
,
ele
,
score
);
znode
=
zslInsert
(
zs
->
zsl
,
score
,
ele
);
zslInsert
(
zs
->
zsl
,
*
score
,
el
e
);
dictAdd
(
zs
->
dict
,
ele
,
&
znode
->
scor
e
);
incrRefCount
(
ele
);
/* added to skiplist */
incrRefCount
(
ele
);
/* added to skiplist */
}
}
}
else
if
(
type
==
REDIS_HASH
)
{
}
else
if
(
type
==
REDIS_HASH
)
{
...
...
src/t_zset.c
View file @
d433ebc6
...
@@ -663,25 +663,23 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
...
@@ -663,25 +663,23 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
* from small to large, all src[i > 0].dict are non-empty too */
* from small to large, all src[i > 0].dict are non-empty too */
di
=
dictGetIterator
(
src
[
0
].
dict
);
di
=
dictGetIterator
(
src
[
0
].
dict
);
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
double
*
score
=
zmalloc
(
sizeof
(
double
))
,
value
;
double
score
,
value
;
*
score
=
src
[
0
].
weight
*
zunionInterDictValue
(
de
);
score
=
src
[
0
].
weight
*
zunionInterDictValue
(
de
);
for
(
j
=
1
;
j
<
setnum
;
j
++
)
{
for
(
j
=
1
;
j
<
setnum
;
j
++
)
{
dictEntry
*
other
=
dictFind
(
src
[
j
].
dict
,
dictGetEntryKey
(
de
));
dictEntry
*
other
=
dictFind
(
src
[
j
].
dict
,
dictGetEntryKey
(
de
));
if
(
other
)
{
if
(
other
)
{
value
=
src
[
j
].
weight
*
zunionInterDictValue
(
other
);
value
=
src
[
j
].
weight
*
zunionInterDictValue
(
other
);
zunionInterAggregate
(
score
,
value
,
aggregate
);
zunionInterAggregate
(
&
score
,
value
,
aggregate
);
}
else
{
}
else
{
break
;
break
;
}
}
}
}
/* skip entry when not present in every source dict */
/* Only continue when present in every source dict. */
if
(
j
!=
setnum
)
{
if
(
j
==
setnum
)
{
zfree
(
score
);
}
else
{
robj
*
o
=
dictGetEntryKey
(
de
);
robj
*
o
=
dictGetEntryKey
(
de
);
znode
=
zslInsert
(
dstzset
->
zsl
,
*
score
,
o
);
znode
=
zslInsert
(
dstzset
->
zsl
,
score
,
o
);
incrRefCount
(
o
);
/* added to skiplist */
incrRefCount
(
o
);
/* added to skiplist */
dictAdd
(
dstzset
->
dict
,
o
,
&
znode
->
score
);
dictAdd
(
dstzset
->
dict
,
o
,
&
znode
->
score
);
incrRefCount
(
o
);
/* added to dictionary */
incrRefCount
(
o
);
/* added to dictionary */
...
@@ -695,11 +693,14 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
...
@@ -695,11 +693,14 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
di
=
dictGetIterator
(
src
[
i
].
dict
);
di
=
dictGetIterator
(
src
[
i
].
dict
);
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
double
score
,
value
;
/* skip key when already processed */
/* skip key when already processed */
if
(
dictFind
(
dstzset
->
dict
,
dictGetEntryKey
(
de
))
!=
NULL
)
continue
;
if
(
dictFind
(
dstzset
->
dict
,
dictGetEntryKey
(
de
))
!=
NULL
)
continue
;
double
*
score
=
zmalloc
(
sizeof
(
double
)),
value
;
/* initialize score */
*
score
=
src
[
i
].
weight
*
zunionInterDictValue
(
de
);
score
=
src
[
i
].
weight
*
zunionInterDictValue
(
de
);
/* because the zsets are sorted by size, its only possible
/* because the zsets are sorted by size, its only possible
* for sets at larger indices to hold this entry */
* for sets at larger indices to hold this entry */
...
@@ -707,12 +708,12 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
...
@@ -707,12 +708,12 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
dictEntry
*
other
=
dictFind
(
src
[
j
].
dict
,
dictGetEntryKey
(
de
));
dictEntry
*
other
=
dictFind
(
src
[
j
].
dict
,
dictGetEntryKey
(
de
));
if
(
other
)
{
if
(
other
)
{
value
=
src
[
j
].
weight
*
zunionInterDictValue
(
other
);
value
=
src
[
j
].
weight
*
zunionInterDictValue
(
other
);
zunionInterAggregate
(
score
,
value
,
aggregate
);
zunionInterAggregate
(
&
score
,
value
,
aggregate
);
}
}
}
}
robj
*
o
=
dictGetEntryKey
(
de
);
robj
*
o
=
dictGetEntryKey
(
de
);
znode
=
zslInsert
(
dstzset
->
zsl
,
*
score
,
o
);
znode
=
zslInsert
(
dstzset
->
zsl
,
score
,
o
);
incrRefCount
(
o
);
/* added to skiplist */
incrRefCount
(
o
);
/* added to skiplist */
dictAdd
(
dstzset
->
dict
,
o
,
&
znode
->
score
);
dictAdd
(
dstzset
->
dict
,
o
,
&
znode
->
score
);
incrRefCount
(
o
);
/* added to dictionary */
incrRefCount
(
o
);
/* added to dictionary */
...
...
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