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.
This commit is contained in:
antirez
2020-04-24 16:49:27 +02:00
parent 57a0c9c98d
commit 8a7f255cd0
4 changed files with 28 additions and 15 deletions

View File

@@ -1006,7 +1006,7 @@ struct redisCommand redisCommandTable[] = {
"admin no-script no-slowlog ok-loading ok-stale",
0,NULL,0,0,0,0,0,0},
{"lcs",lcsCommand,-4,
{"stralgo",stralgoCommand,-2,
"write use-memory @string",
0,lcsGetKeys,0,0,0,0,0,0}
};

View File

@@ -2389,7 +2389,7 @@ void xdelCommand(client *c);
void xtrimCommand(client *c);
void lolwutCommand(client *c);
void aclCommand(client *c);
void lcsCommand(client *c);
void stralgoCommand(client *c);
#if defined(__GNUC__)
void *calloc(size_t count, size_t size) __attribute__ ((deprecated));

View File

@@ -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;