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
4cbf3f5d
Commit
4cbf3f5d
authored
Apr 01, 2020
by
antirez
Browse files
LCS: other fixes to range emission.
parent
c9c03c3e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/t_string.c
View file @
4cbf3f5d
...
@@ -584,12 +584,13 @@ void lcsCommand(client *c) {
...
@@ -584,12 +584,13 @@ void lcsCommand(client *c) {
i
=
alen
,
j
=
blen
;
i
=
alen
,
j
=
blen
;
while
(
computelcs
&&
i
>
0
&&
j
>
0
)
{
while
(
computelcs
&&
i
>
0
&&
j
>
0
)
{
int
emit_range
=
0
;
if
(
a
[
i
-
1
]
==
b
[
j
-
1
])
{
if
(
a
[
i
-
1
]
==
b
[
j
-
1
])
{
/* If there is a match, store the character and reduce
/* If there is a match, store the character and reduce
* the indexes to look for a new match. */
* the indexes to look for a new match. */
result
[
idx
-
1
]
=
a
[
i
-
1
];
result
[
idx
-
1
]
=
a
[
i
-
1
];
/* Track the current range. */
/* Track the current range. */
int
emit_range
=
0
;
if
(
arange_start
==
alen
)
{
if
(
arange_start
==
alen
)
{
arange_start
=
i
-
1
;
arange_start
=
i
-
1
;
arange_end
=
i
-
1
;
arange_end
=
i
-
1
;
...
@@ -605,22 +606,9 @@ void lcsCommand(client *c) {
...
@@ -605,22 +606,9 @@ void lcsCommand(client *c) {
emit_range
=
1
;
emit_range
=
1
;
}
}
}
}
/* Emit the range if we matched with the first byte of
* one of the two strings. We'll exit the loop ASAP. */
if
(
arange_start
==
0
||
brange_start
==
0
)
emit_range
=
1
;
if
(
arange_start
==
0
||
brange_start
==
0
)
emit_range
=
1
;
/* Emit the current range if needed. */
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
);
}
arange_start
=
alen
;
/* Restart at the next match. */
arraylen
++
;
}
idx
--
;
i
--
;
j
--
;
idx
--
;
i
--
;
j
--
;
}
else
{
}
else
{
/* Otherwise reduce i and j depending on the largest
/* Otherwise reduce i and j depending on the largest
...
@@ -631,6 +619,22 @@ void lcsCommand(client *c) {
...
@@ -631,6 +619,22 @@ void lcsCommand(client *c) {
i
--
;
i
--
;
else
else
j
--
;
j
--
;
if
(
arange_start
!=
alen
)
emit_range
=
1
;
}
/* Emit the current range if needed. */
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
);
}
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