Commit 5f5b9840 authored by antirez's avatar antirez
Browse files

Partial qsort implemented in SORT command, only when both BY and LIMIT is...

Partial qsort implemented in SORT command, only when both BY and LIMIT is used. minor fix for a warning compiling under Linux.
parent 75fd597d
...@@ -6,7 +6,7 @@ DEBUG?= -g ...@@ -6,7 +6,7 @@ DEBUG?= -g
CFLAGS?= -std=c99 -pedantic -O2 -Wall -W -DSDS_ABORT_ON_OOM CFLAGS?= -std=c99 -pedantic -O2 -Wall -W -DSDS_ABORT_ON_OOM
CCOPT= $(CFLAGS) CCOPT= $(CFLAGS)
OBJ = adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o OBJ = adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o
BENCHOBJ = ae.o anet.o benchmark.o sds.o adlist.o zmalloc.o BENCHOBJ = ae.o anet.o benchmark.o sds.o adlist.o zmalloc.o
CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "fmacros.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -10,6 +10,6 @@ ...@@ -10,6 +10,6 @@
void void
pqsort(void *a, size_t n, size_t es, pqsort(void *a, size_t n, size_t es,
int (*cmp) __P((const void *, const void *)), size_t lrange, size_t rrange) int (*cmp) __P((const void *, const void *)), size_t lrange, size_t rrange);
#endif #endif
...@@ -56,7 +56,8 @@ ...@@ -56,7 +56,8 @@
#include "dict.h" /* Hash tables */ #include "dict.h" /* Hash tables */
#include "adlist.h" /* Linked lists */ #include "adlist.h" /* Linked lists */
#include "zmalloc.h" /* total memory usage aware version of malloc/free */ #include "zmalloc.h" /* total memory usage aware version of malloc/free */
#include "lzf.h" #include "lzf.h" /* LZF compression library */
#include "pqsort.h" /* Partial qsort for SORT+LIMIT */
/* Error codes */ /* Error codes */
#define REDIS_OK 0 #define REDIS_OK 0
...@@ -3426,7 +3427,10 @@ static void sortCommand(redisClient *c) { ...@@ -3426,7 +3427,10 @@ static void sortCommand(redisClient *c) {
server.sort_desc = desc; server.sort_desc = desc;
server.sort_alpha = alpha; server.sort_alpha = alpha;
server.sort_bypattern = sortby ? 1 : 0; server.sort_bypattern = sortby ? 1 : 0;
qsort(vector,vectorlen,sizeof(redisSortObject),sortCompare); if (sortby && (start != 0 || end != vectorlen-1))
pqsort(vector,vectorlen,sizeof(redisSortObject),sortCompare, start,end);
else
qsort(vector,vectorlen,sizeof(redisSortObject),sortCompare);
} }
/* Send command output to the output buffer, performing the specified /* Send command output to the output buffer, performing the specified
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment