Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/Modules/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(VALKEY_SERVER_SRCS
${CMAKE_SOURCE_DIR}/src/t_list.c
${CMAKE_SOURCE_DIR}/src/t_set.c
${CMAKE_SOURCE_DIR}/src/t_zset.c
${CMAKE_SOURCE_DIR}/src/skiplist.c
${CMAKE_SOURCE_DIR}/src/t_hash.c
${CMAKE_SOURCE_DIR}/src/config.c
${CMAKE_SOURCE_DIR}/src/aof.c
Expand Down
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ ENGINE_SERVER_OBJ = \
t_stream.o \
t_string.o \
t_zset.o \
skiplist.o \
threads_mngr.o \
timeout.o \
tls.o \
Expand Down
1 change: 1 addition & 0 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/

#include "server.h"
#include "skiplist.h"
#include "bio.h"
#include "rio.h"
#include "functions.h"
Expand Down
1 change: 1 addition & 0 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/

#include "server.h"
#include "skiplist.h"
#include "cluster.h"
#include "cluster_migrateslots.h"
#include "latency.h"
Expand Down
1 change: 1 addition & 0 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/

#include "server.h"
#include "skiplist.h"
#include "util.h"
#include "sha1.h" /* SHA1 is used for DEBUG DIGEST */
#include "crc64.h"
Expand Down
1 change: 1 addition & 0 deletions src/defrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*/

#include "server.h"
#include "skiplist.h"
#include "hashtable.h"
#include "eval.h"
#include "script.h"
Expand Down
1 change: 1 addition & 0 deletions src/geo.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

#include "geo.h"
#include "skiplist.h"
#include "geohash_helper.h"
#include "debugmacro.h"
#include "pqsort.h"
Expand Down
1 change: 1 addition & 0 deletions src/lazyfree.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "server.h"
#include "skiplist.h"
#include "bio.h"
#include "functions.h"
#include "cluster.h"
Expand Down
1 change: 1 addition & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* function names. For details, see the script src/modules/gendoc.rb.
* -------------------------------------------------------------------------- */
#include "server.h"
#include "skiplist.h"
#include "cluster.h"
#include "commandlog.h"
#include "rdb.h"
Expand Down
1 change: 1 addition & 0 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "hashtable.h"
#include "server.h"
#include "skiplist.h"
#include "serverassert.h"
#include "functions.h"
#include "intset.h" /* Compact integer set structure */
Expand Down
1 change: 1 addition & 0 deletions src/rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "hashtable.h"
#include "server.h"
#include "skiplist.h"
#include "lzf.h" /* LZF compression library */
#include "zipmap.h"
#include "endianconv.h"
Expand Down
1 change: 1 addition & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "server.h"
#include "skiplist.h"
#include "connection.h"
#include "monotonic.h"
#include "cluster.h"
Expand Down
53 changes: 3 additions & 50 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,6 @@ typedef enum {
#define SUPERVISED_SYSTEMD 2
#define SUPERVISED_UPSTART 3

#define ZSKIPLIST_MAXLEVEL 32 /* Should be enough for 2^64 elements */
#define ZSKIPLIST_MAX_SEARCH 10

/* Append only defines */
#define REPL_MAX_WRITTEN_BEFORE_FSYNC (1024 * 1024 * 8) /* 8 MB */
Expand Down Expand Up @@ -1490,41 +1488,12 @@ struct sharedObjectsStruct {
sds minstring, maxstring;
};

/* ZSETs use a specialized version of Skiplists */
typedef struct zskiplistNode {
union {
double score; /* Sorting score for node ordering. */
unsigned long length; /* Number of elements in the skiplist. */
};
union {
struct zskiplistNode *backward; /* Pointer to previous node for reverse traversal. */
struct zskiplistNode *tail; /* Tail element of the skiplist. */
};
struct zskiplistLevel {
struct zskiplistNode *forward;
/* At each level we keep the span, which is the number of elements which are on the "subtree"
* from this node at this level to the next node at the same level.
* One exception is the value at level 0. In level 0 the span can only be 1 or 0 (in case the last elements in the list)
* So we use it in order to hold the height of the node, which is the number of levels. */
unsigned long span;
} level[1]; /* Flexible array member - actual levels determined at node creation. */
/* For non-header nodes, after the level[], sds header length (1 byte) and an embedded sds element are stored. */
} zskiplistNode;

/* The header node does not store actual data (no score, no backward pointer,
* and its node height is fixed at ZSKIPLIST_MAXLEVEL).
* To save memory, we reuse the memory space of these fields in the header node to store:
* - skiplist length (number of elements)
* - tail pointer to the last element
* - maximum current level of the skiplist
* For detailed memory layout, refer to the zskiplistNode struct definition. */
typedef struct zskiplist {
zskiplistNode header;
} zskiplist;
/* Skiplist types - full definitions in skiplist.h */
struct zskiplist;

typedef struct zset {
hashtable *ht;
zskiplist *zsl;
struct zskiplist *zsl;
} zset;

typedef struct clientBufferLimitsConfig {
Expand Down Expand Up @@ -3401,17 +3370,6 @@ typedef struct {
#define ERROR_COMMAND_REJECTED (1 << 0) /* Indicate to update the command rejected stats */
#define ERROR_COMMAND_FAILED (1 << 1) /* Indicate to update the command failed stats */

zskiplist *zslCreate(void);
int zslGetHeight(const zskiplist *zsl);
zskiplistNode *zslGetTail(const zskiplist *zsl);
void zslSetTail(zskiplist *zsl, zskiplistNode *tail);
unsigned long zslGetLength(const zskiplist *zsl);
zskiplistNode *zslGetHeader(zskiplist *zsl);
size_t zslGetAllocSize(void);
void zslFree(zskiplist *zsl);
zskiplistNode *zslInsert(zskiplist *zsl, double score, const_sds ele);
zskiplistNode *zslNthInRange(zskiplist *zsl, zrangespec *range, long n, long *rank);
sds zslGetNodeElement(const zskiplistNode *x);
double zzlGetScore(unsigned char *sptr);
void zzlNext(unsigned char *zl, unsigned char **eptr, unsigned char **sptr);
void zzlPrev(unsigned char *zl, unsigned char **eptr, unsigned char **sptr);
Expand All @@ -3434,17 +3392,12 @@ void genericZpopCommand(client *c,
int reply_nil_when_empty,
int *deleted);
sds lpGetObject(unsigned char *sptr);
int zslValueGteMin(double value, zrangespec *spec);
int zslValueLteMax(double value, zrangespec *spec);
void zsetFreeLexRange(zlexrangespec *spec);
int zsetParseLexRange(robj *min, robj *max, zlexrangespec *spec);
unsigned char *zzlFirstInLexRange(unsigned char *zl, zlexrangespec *range);
unsigned char *zzlLastInLexRange(unsigned char *zl, zlexrangespec *range);
zskiplistNode *zslNthInLexRange(zskiplist *zsl, zlexrangespec *range, long n);
int zzlLexValueGteMin(unsigned char *p, zlexrangespec *spec);
int zzlLexValueLteMax(unsigned char *p, zlexrangespec *spec);
int zslLexValueGteMin(sds value, zlexrangespec *spec);
int zslLexValueLteMax(sds value, zlexrangespec *spec);

/* Core functions */
int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *level);
Expand Down
Loading
Loading