MCPcopy Create free account
hub / github.com/F-Stack/f-stack / stralgoLCS

Function stralgoLCS

app/redis-6.2.6/src/t_string.c:729–955  ·  view source on GitHub ↗

STRALGO [IDX] [LEN] [MINMATCHLEN ] [WITHMATCHLEN] * STRINGS | KEYS */

Source from the content-addressed store, hash-verified

727 * STRINGS <string> <string> | KEYS <keya> <keyb>
728 */
729void stralgoLCS(client *c) {
730 uint32_t i, j;
731 long long minmatchlen = 0;
732 sds a = NULL, b = NULL;
733 int getlen = 0, getidx = 0, withmatchlen = 0;
734 robj *obja = NULL, *objb = NULL;
735
736 for (j = 2; j < (uint32_t)c->argc; j++) {
737 char *opt = c->argv[j]->ptr;
738 int moreargs = (c->argc-1) - j;
739
740 if (!strcasecmp(opt,"IDX")) {
741 getidx = 1;
742 } else if (!strcasecmp(opt,"LEN")) {
743 getlen = 1;
744 } else if (!strcasecmp(opt,"WITHMATCHLEN")) {
745 withmatchlen = 1;
746 } else if (!strcasecmp(opt,"MINMATCHLEN") && moreargs) {
747 if (getLongLongFromObjectOrReply(c,c->argv[j+1],&minmatchlen,NULL)
748 != C_OK) goto cleanup;
749 if (minmatchlen < 0) minmatchlen = 0;
750 j++;
751 } else if (!strcasecmp(opt,"STRINGS") && moreargs > 1) {
752 if (a != NULL) {
753 addReplyError(c,"Either use STRINGS or KEYS");
754 goto cleanup;
755 }
756 a = c->argv[j+1]->ptr;
757 b = c->argv[j+2]->ptr;
758 j += 2;
759 } else if (!strcasecmp(opt,"KEYS") && moreargs > 1) {
760 if (a != NULL) {
761 addReplyError(c,"Either use STRINGS or KEYS");
762 goto cleanup;
763 }
764 obja = lookupKeyRead(c->db,c->argv[j+1]);
765 objb = lookupKeyRead(c->db,c->argv[j+2]);
766 if ((obja && obja->type != OBJ_STRING) ||
767 (objb && objb->type != OBJ_STRING))
768 {
769 addReplyError(c,
770 "The specified keys must contain string values");
771 /* Don't cleanup the objects, we need to do that
772 * only after calling getDecodedObject(). */
773 obja = NULL;
774 objb = NULL;
775 goto cleanup;
776 }
777 obja = obja ? getDecodedObject(obja) : createStringObject("",0);
778 objb = objb ? getDecodedObject(objb) : createStringObject("",0);
779 a = obja->ptr;
780 b = objb->ptr;
781 j += 2;
782 } else {
783 addReplyErrorObject(c,shared.syntaxerr);
784 goto cleanup;
785 }
786 }

Callers 1

stralgoCommandFunction · 0.85

Calls 15

strcasecmpFunction · 0.85
addReplyErrorFunction · 0.85
lookupKeyReadFunction · 0.85
getDecodedObjectFunction · 0.85
addReplyErrorObjectFunction · 0.85
sdslenFunction · 0.85
ztrymallocFunction · 0.85
sdsnewlenFunction · 0.85
addReplyMapLenFunction · 0.85
addReplyBulkCStringFunction · 0.85
addReplyDeferredLenFunction · 0.85

Tested by

no test coverage detected