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
45290ad9
Commit
45290ad9
authored
Feb 10, 2011
by
Pieter Noordhuis
Browse files
Rename zset range functions
parent
8e1b3277
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/t_zset.c
View file @
45290ad9
...
@@ -180,16 +180,16 @@ typedef struct {
...
@@ -180,16 +180,16 @@ typedef struct {
int
minex
,
maxex
;
/* are min or max exclusive? */
int
minex
,
maxex
;
/* are min or max exclusive? */
}
zrangespec
;
}
zrangespec
;
static
int
zslValue
InMinRange
(
double
value
,
zrangespec
*
spec
)
{
static
int
zslValue
GteMin
(
double
value
,
zrangespec
*
spec
)
{
return
spec
->
minex
?
(
value
>
spec
->
min
)
:
(
value
>=
spec
->
min
);
return
spec
->
minex
?
(
value
>
spec
->
min
)
:
(
value
>=
spec
->
min
);
}
}
static
int
zslValue
InMaxRange
(
double
value
,
zrangespec
*
spec
)
{
static
int
zslValue
LteMax
(
double
value
,
zrangespec
*
spec
)
{
return
spec
->
maxex
?
(
value
<
spec
->
max
)
:
(
value
<=
spec
->
max
);
return
spec
->
maxex
?
(
value
<
spec
->
max
)
:
(
value
<=
spec
->
max
);
}
}
static
int
zslValueInRange
(
double
value
,
zrangespec
*
spec
)
{
static
int
zslValueInRange
(
double
value
,
zrangespec
*
spec
)
{
return
zslValue
InMinRange
(
value
,
spec
)
&&
zslValue
InMaxRange
(
value
,
spec
);
return
zslValue
GteMin
(
value
,
spec
)
&&
zslValue
LteMax
(
value
,
spec
);
}
}
/* Returns if there is a part of the zset is in range. */
/* Returns if there is a part of the zset is in range. */
...
@@ -201,10 +201,10 @@ int zslIsInRange(zskiplist *zsl, zrangespec *range) {
...
@@ -201,10 +201,10 @@ int zslIsInRange(zskiplist *zsl, zrangespec *range) {
(
range
->
min
==
range
->
max
&&
(
range
->
minex
||
range
->
maxex
)))
(
range
->
min
==
range
->
max
&&
(
range
->
minex
||
range
->
maxex
)))
return
0
;
return
0
;
x
=
zsl
->
tail
;
x
=
zsl
->
tail
;
if
(
x
==
NULL
||
!
zslValue
InMinRange
(
x
->
score
,
range
))
if
(
x
==
NULL
||
!
zslValue
GteMin
(
x
->
score
,
range
))
return
0
;
return
0
;
x
=
zsl
->
header
->
level
[
0
].
forward
;
x
=
zsl
->
header
->
level
[
0
].
forward
;
if
(
x
==
NULL
||
!
zslValue
InMaxRange
(
x
->
score
,
range
))
if
(
x
==
NULL
||
!
zslValue
LteMax
(
x
->
score
,
range
))
return
0
;
return
0
;
return
1
;
return
1
;
}
}
...
@@ -222,7 +222,7 @@ zskiplistNode *zslFirstInRange(zskiplist *zsl, zrangespec range) {
...
@@ -222,7 +222,7 @@ zskiplistNode *zslFirstInRange(zskiplist *zsl, zrangespec range) {
for
(
i
=
zsl
->
level
-
1
;
i
>=
0
;
i
--
)
{
for
(
i
=
zsl
->
level
-
1
;
i
>=
0
;
i
--
)
{
/* Go forward while *OUT* of range. */
/* Go forward while *OUT* of range. */
while
(
x
->
level
[
i
].
forward
&&
while
(
x
->
level
[
i
].
forward
&&
!
zslValue
InMinRange
(
x
->
level
[
i
].
forward
->
score
,
&
range
))
!
zslValue
GteMin
(
x
->
level
[
i
].
forward
->
score
,
&
range
))
x
=
x
->
level
[
i
].
forward
;
x
=
x
->
level
[
i
].
forward
;
}
}
...
@@ -246,7 +246,7 @@ zskiplistNode *zslLastInRange(zskiplist *zsl, zrangespec range) {
...
@@ -246,7 +246,7 @@ zskiplistNode *zslLastInRange(zskiplist *zsl, zrangespec range) {
for
(
i
=
zsl
->
level
-
1
;
i
>=
0
;
i
--
)
{
for
(
i
=
zsl
->
level
-
1
;
i
>=
0
;
i
--
)
{
/* Go forward while *IN* range. */
/* Go forward while *IN* range. */
while
(
x
->
level
[
i
].
forward
&&
while
(
x
->
level
[
i
].
forward
&&
zslValue
InMaxRange
(
x
->
level
[
i
].
forward
->
score
,
&
range
))
zslValue
LteMax
(
x
->
level
[
i
].
forward
->
score
,
&
range
))
x
=
x
->
level
[
i
].
forward
;
x
=
x
->
level
[
i
].
forward
;
}
}
...
@@ -979,9 +979,9 @@ void genericZrangebyscoreCommand(redisClient *c, int reverse, int justcount) {
...
@@ -979,9 +979,9 @@ void genericZrangebyscoreCommand(redisClient *c, int reverse, int justcount) {
while
(
ln
&&
limit
--
)
{
while
(
ln
&&
limit
--
)
{
/* Abort when the node is no longer in range. */
/* Abort when the node is no longer in range. */
if
(
reverse
)
{
if
(
reverse
)
{
if
(
!
zslValue
InMinRange
(
ln
->
score
,
&
range
))
break
;
if
(
!
zslValue
GteMin
(
ln
->
score
,
&
range
))
break
;
}
else
{
}
else
{
if
(
!
zslValue
InMaxRange
(
ln
->
score
,
&
range
))
break
;
if
(
!
zslValue
LteMax
(
ln
->
score
,
&
range
))
break
;
}
}
/* Do our magic */
/* Do our magic */
...
...
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