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
56a52e80
Commit
56a52e80
authored
Apr 02, 2020
by
antirez
Browse files
LCS: MINMATCHLEN and WITHMATCHLEN options.
parent
ebb09a5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/t_string.c
View file @
56a52e80
...
...
@@ -482,11 +482,13 @@ void strlenCommand(client *c) {
/* LCS -- Longest common subsequence.
*
* LCS [IDX] [STOREIDX <key>] STRINGS <string> <string> | KEYS <keya> <keyb> */
* LCS [IDX] [STOREIDX <key>] [MINMATCHLEN <len>]
* STRINGS <string> <string> | KEYS <keya> <keyb> */
void
lcsCommand
(
client
*
c
)
{
uint32_t
i
,
j
;
long
long
minmatchlen
=
0
;
sds
a
=
NULL
,
b
=
NULL
;
int
getlen
=
0
,
getidx
=
0
;
int
getlen
=
0
,
getidx
=
0
,
withmatchlen
=
0
;
robj
*
idxkey
=
NULL
;
/* STOREIDX will set this and getidx to 1. */
robj
*
obja
=
NULL
,
*
objb
=
NULL
;
...
...
@@ -498,10 +500,17 @@ void lcsCommand(client *c) {
getidx
=
1
;
}
else
if
(
!
strcasecmp
(
opt
,
"LEN"
))
{
getlen
=
1
;
}
else
if
(
!
strcasecmp
(
opt
,
"WITHMATCHLEN"
))
{
withmatchlen
=
1
;
}
else
if
(
!
strcasecmp
(
opt
,
"STOREIDX"
)
&&
moreargs
)
{
getidx
=
1
;
idxkey
=
c
->
argv
[
j
+
1
];
j
++
;
}
else
if
(
!
strcasecmp
(
opt
,
"MINMATCHLEN"
)
&&
moreargs
)
{
if
(
getLongLongFromObjectOrReply
(
c
,
c
->
argv
[
j
+
1
],
&
minmatchlen
,
NULL
)
!=
C_OK
)
return
;
if
(
minmatchlen
<
0
)
minmatchlen
=
0
;
j
++
;
}
else
if
(
!
strcasecmp
(
opt
,
"STRINGS"
))
{
if
(
moreargs
!=
2
)
{
addReplyError
(
c
,
"LCS requires exactly two strings"
);
...
...
@@ -637,18 +646,22 @@ void lcsCommand(client *c) {
}
/* Emit the current range if needed. */
uint32_t
match_len
=
arange_end
-
arange_start
+
1
;
if
(
emit_range
)
{
if
(
arraylenptr
)
{
addReplyArrayLen
(
c
,
2
);
addReplyArrayLen
(
c
,
2
);
addReplyLongLong
(
c
,
arange_start
);
addReplyLongLong
(
c
,
arange_end
);
addReplyArrayLen
(
c
,
2
);
addReplyLongLong
(
c
,
brange_start
);
addReplyLongLong
(
c
,
brange_end
);
if
(
minmatchlen
==
0
||
match_len
>=
minmatchlen
)
{
if
(
arraylenptr
)
{
addReplyArrayLen
(
c
,
2
+
withmatchlen
);
addReplyArrayLen
(
c
,
2
);
addReplyLongLong
(
c
,
arange_start
);
addReplyLongLong
(
c
,
arange_end
);
addReplyArrayLen
(
c
,
2
);
addReplyLongLong
(
c
,
brange_start
);
addReplyLongLong
(
c
,
brange_end
);
if
(
withmatchlen
)
addReplyLongLong
(
c
,
match_len
);
arraylen
++
;
}
}
arange_start
=
alen
;
/* Restart at the next match. */
arraylen
++
;
}
}
...
...
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