diff options
author | antirez <antirez@gmail.com> | 2020-04-24 16:49:27 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2020-04-24 16:54:32 +0200 |
commit | 8a7f255cd005a13aaebb77468ab77dc2c6501d23 (patch) | |
tree | 862ecc07d1af4fecf43b5447aef379b077581bca /src/t_string.c | |
parent | 57a0c9c98d3bb966d6191fd1657df010cfe060fb (diff) | |
download | redis-8a7f255cd005a13aaebb77468ab77dc2c6501d23.tar.gz |
LCS -> STRALGO LCS.
STRALGO should be a container for mostly read-only string
algorithms in Redis. The algorithms should have two main
characteristics:
1. They should be non trivial to compute, and often not part of
programming language standard libraries.
2. They should be fast enough that it is a good idea to have optimized C
implementations.
Next thing I would love to see? A small strings compression algorithm.
Diffstat (limited to 'src/t_string.c')
-rw-r--r-- | src/t_string.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/t_string.c b/src/t_string.c index ef382bb0c..d4eb04769 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -480,18 +480,31 @@ void strlenCommand(client *c) { addReplyLongLong(c,stringObjectLen(o)); } -/* LCS -- Longest common subsequence. + +/* STRALGO -- Implement complex algorithms on strings. * - * LCS [IDX] [MINMATCHLEN <len>] - * STRINGS <string> <string> | KEYS <keya> <keyb> */ -void lcsCommand(client *c) { + * STRALGO <algorithm> ... arguments ... */ +void stralgoLCS(client *c); /* This implements the LCS algorithm. */ +void stralgoCommand(client *c) { + /* Select the algorithm. */ + if (!strcasecmp(c->argv[1]->ptr,"lcs")) { + stralgoLCS(c); + } else { + addReply(c,shared.syntaxerr); + } +} + +/* STRALGO <algo> [IDX] [MINMATCHLEN <len>] [WITHMATCHLEN] + * STRINGS <string> <string> | KEYS <keya> <keyb> + */ +void stralgoLCS(client *c) { uint32_t i, j; long long minmatchlen = 0; sds a = NULL, b = NULL; int getlen = 0, getidx = 0, withmatchlen = 0; robj *obja = NULL, *objb = NULL; - for (j = 1; j < (uint32_t)c->argc; j++) { + for (j = 2; j < (uint32_t)c->argc; j++) { char *opt = c->argv[j]->ptr; int moreargs = (c->argc-1) - j; |